Set Validation Rule For Specific Characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • killuminati
    New Member
    • Jun 2007
    • 4

    #1

    Set Validation Rule For Specific Characters

    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?
    Last edited by ADezii; Jun 22 '07, 11:17 AM. Reason: Modified Post Title
  • mandy1
    New Member
    • Jun 2007
    • 7

    #2
    Originally posted by killuminati
    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?

    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)

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by killuminati
      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?
      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:
      1. 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]
      2. 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]
      3. Good Luck.

      Comment

      • killuminati
        New Member
        • Jun 2007
        • 4

        #4
        Thanks alot everyone.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by killuminati
          Thanks alot everyone.
          You're quite welcome.

          Comment

          Working...