Results 1 to 7 of 7

Thread: Textbox Validation....

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    Textbox Validation....

    How can I validate the text that the user types in on keyup to detect wither or not the data is either a-z, A-Z, 0-9, or with these two characters -.

    thank you.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    surely the key press event is the better and then you can evaluate the ascii character and filter it as acceptable or not, either setting e.handled to true or false as you wish

  3. #3

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    validation

    do you know the ascii range for those characters or where to find them? thank you.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can use RegularExpressions. I didn't test this but it should get you in the right direction:
    VB Code:
    1. Dim regex As New System.Text.RegularExpressions.Regex("\w")
    2.         e.Handled = Not regex.IsMatch(TextBox1.Text.Substring(TextBox1.Text.Length - 1))

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by Edneeis
    You can use RegularExpressions. I didn't test this but it should get you in the right direction:
    Just a question of my interest, not very related to his problem: Wouldn't RegEx use more resources than using Char.IsLetter(). I mean in simple validation situations, which one is prefered?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I don't know, but I don't think RegEx is very resource heavy. Although calling IsLetter and IsNumeric is probably the better solution. Sometimes I have a habit of overlooking the obvious.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    In answer to the do I know the ascii code range numbers, the simple answer is no, but I get them by typing in 'ascii codes' into the search into the msdn help for VS 2002.

    Unfortunately the help for VS 2003 is all on MSDN but the same search phrase should yield the same reults there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width