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.
Printable View
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.
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
do you know the ascii range for those characters or where to find them? thank you.
You can use RegularExpressions. I didn't test this but it should get you in the right direction:
VB Code:
Dim regex As New System.Text.RegularExpressions.Regex("\w") e.Handled = Not regex.IsMatch(TextBox1.Text.Substring(TextBox1.Text.Length - 1))
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?Quote:
Originally posted by Edneeis
You can use RegularExpressions. I didn't test this but it should get you in the right direction:
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. :)
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.