|
-
Oct 13th, 2003, 03:55 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 13th, 2003, 04:17 PM
#2
Hyperactive Member
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
-
Oct 13th, 2003, 06:39 PM
#3
Thread Starter
Hyperactive Member
validation
do you know the ascii range for those characters or where to find them? thank you.
-
Oct 13th, 2003, 07:37 PM
#4
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))
-
Oct 13th, 2003, 09:31 PM
#5
Frenzied Member
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
-
Oct 13th, 2003, 09:35 PM
#6
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.
-
Oct 14th, 2003, 05:27 PM
#7
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|