Hi there. I am studying ICT at a college in cumbria. I have been trying to get a validation rule set-up which allows me to enter alpha characters only, but hypens and apostrophes are allowed. I have set-up the alpha characters only bit (i have used the input mask ??????????????? ??????????????? ???;1;" ") but I just cannot find a way to get the rule to allow hyphens and apostrophes. Can someone please help?
Set Validation Rule For Specific Characters
Collapse
X
-
-
Originally posted by killuminatiHi there. I am studying ICT at a college in cumbria. I have been trying to get a validation rule set-up which allows me to enter alpha characters only, but hypens and apostrophes are allowed. I have set-up the alpha characters only bit (i have used the input mask ??????????????? ??????????????? ???;1;" ") but I just cannot find a way to get the rule to allow hyphens and apostrophes. Can someone please help?
hi
u can write follwing in the validation rule.
Like "*-*"
where fist * means any character can be placed before the - sign and second * means any character can be placed after the - sign.
if u want to apply two conditions then u can use the following
Like "*-*" OR "*#*"
where # can be any special character that u want to use for your condition.
hope this will help u
is it works for u?
With Regards
Mandy(Mandeep) -
Rather than a Validation Rule, I prefer to maintain precise control over each Keystroke entered into a Text Box on a Form. The following code, in the KeyPress() Event of a Text Box, will allow only Alpha characters, -, ', or Backspace, anything else will be negated. If you are interested in using this approach:Originally posted by killuminatiHi there. I am studying ICT at a college in cumbria. I have been trying to get a validation rule set-up which allows me to enter alpha characters only, but hypens and apostrophes are allowed. I have set-up the alpha characters only bit (i have used the input mask ??????????????? ??????????????? ???;1;" ") but I just cannot find a way to get the rule to allow hyphens and apostrophes. Can someone please help?
- You must Declare the IsCharAlpha() Function in a Standard Code Module (see this Week's Tip).
[CODE=vb]Public Declare Function IsCharAlpha Lib "User32" Alias "IsCharAlph aA" (ByVal cChar As Byte) As Long[/CODE] - Copy and Paste the following code segment into the KeyPress() Event of the Text Box for which you want to maintain Validation.
[CODE=vb]Private Sub TextButton_KeyP ress(KeyAscii As Integer)
Const conApostrophe = 39
Const conHyphen = 45
Const conBackspace = 8
If IsCharAlpha(Key Ascii) Or KeyAscii = conApostrophe Or KeyAscii = conHyphen _
Or KeyAscii = conBackspace Then
'it is either an Alpha, ', -, or Backspace and it's OK
Else
'Negate the Keystroke
KeyAscii = 0
End If
End Sub[/CODE] - Good Luck.
Comment
- You must Declare the IsCharAlpha() Function in a Standard Code Module (see this Week's Tip).
-
Comment