By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,200 Members | 1,755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,200 IT Pros & Developers. It's quick & easy.

Phone number regular expressions

P: n/a
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

May 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/U...-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)

venu wrote: 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


May 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.