Validate Text - Name, Phone Etc

D

Dragon

Hi,

I am trying to find out if there is a good (Built-in?) way to validate text
input. I would like to check a textbox to see whether user enter a proper
name (without numbers, symbols etc) or if it is a valid phone number (no
letters or symbols) etc or not. Right now I am sending the string to a
subroutine that check it each letter at a time (looping) and tries to match
it with pre-drfined chars using select case. This seems like very
inefficient way of doing this.

I would like to create these validation methods of a class and reuse them in
all my programs.

Any ideas?
Thanks.
 
D

Dragon

Thank you Tom.

Would you be able to help me a bit more? I am readin up on regular
expressions but, for some reason, I am a bit confused. It seems I am doing
pretty much ( or close to ) same thing I was doing when comparing one letter
at a time.

For example, I have a string "Jon9y Smith" and I want to make sure that it
is a valid name or not. I will have to either check each char at a time to
make sure there is no char ourside (a-z, A-Z, " ") orsimply check for a
space and assume the names are typed correctly.

Am I missing something here? Any better example I could look at?

thank you.
 
W

Will Lastname

Regular Expression validation is the way to go.

\d - will find any digits in the string
[0-9] - digits 0 - 9
[~!@#$%^&*()-_+=\|][{}<>?,./] - self-explanatory
 
D

Dragon

Thank you Will.

I am beginning to understand that I can easily exclude certain characters.
The main problem I have with this method is that there are too many to
exclude. A user can easily add non a-z char by simply using the Alt
combination. Trying to exclude each one of those could take forever.

I guess I will do some more research to see if I can have an 'include' list
instead of 'exclude' list.

Thank you.
 
D

Dragon

Thank you Cor. I will definately have to give it a try. What would you say
which method is better, more efficient, using MaskedTextBox or using Regular
Expressions?

Thanks.
 
C

Cor Ligthert [MVP]

Dragon,

I did not use the MaskedTextBox yet and probably are not able to do that for
a telephon number (we have in Europa a lot of formats for that, only here in
Holland there are even more than one), however I think if you are able to
use it, than it will obviously be better because it is more direct to the
user.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top