Validate US Phone number with Regular Expression

O

Ori

Hi,

I'm looking for a good way to validate a US phone number and i though
using regular expression for this.
I want to support 3 different ways to enter a phone number:
1.Local Phone : 888-8899
2.With extension: (310)888-2569
3.With extension + 1 : 1(888)789-2569

Can someone tell me what expression I can us in order to support those
3 methods at once ?

Thanks,

Ori.
 
M

Michael

I feel it's much more rewarding to do your own regex's, unless you are
really stumped at something (this example is not that hard by the way)

If you would like to learn how to do it yourself, I would suggest this site,
it has many examples. http://regexplib.com

And there are many tutorial sites to help you as well.
http://gnosis.cx/publish/programming/regular_expressions.html
http://www.regular-expressions.info/

Basically the easiest way to do this one is to use the | delimiter to
specify three different regex's for each phone number.
firstway|secondway|thirdway. The first way would be something like this
\d{3}-\d{4}. If you really wanted to have fun, you could probably do this
without using the | operator, but I wouldn't do that if this is your first
regex experience.

HTH,
--Michael
 
B

Brian W

Check out the RegularExpressionValidator control

The designer will give you a starting point (check the ValidationExpression
property in the property browser)

HTH
Brian W
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top