Phone number regular expressions

V

venu

Hi,
I have a different requirement and it is :

I need to validate a phone number field.
It may or may not be a US phone number.

The constraints are :
***********************

# It should accept any number of numbers
# any number of - hyphens
# and one + symbol
# no other characters and alphabets are allowed

Thanks in advance

Venugopal.S
 
J

james.curran

First, in time like these, you should first check www.regexlib.com
which have a number of regex expression, free for the copying.

You may also want to try the "Regular Expression Workbench"
(http://www.gotdotnet.com/Community/...mpleGuid=C712F2DF-B026-4D58-8961-4EE2729D7322).
Also free, and how I wrote this.

But, this seemed simple enough to try myself -- with one exception:
# and one + symbol

I'm going to assume that it's only allowed as the first character:
^\+?[-\d]*$

^ (anchor to start of string)
+
? (zero or one time)
Any character in "-\d"
* (zero or more times)
$ (anchor to end of string)
 

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