Phone number regex

T

tJ

Hi

I'd like to validate a string input as a phone number using a regex
matcher. This is the criteria:
* at least 10 numbers,
* only numeric and the following special characters should be allowed:
'+' '-' '(' ')' and spaces

The closest I've been able to find is ^[-\d()\s]*$ :-(

Thank you in advance,
tJ
 
M

Michael Nemtsev

Hello TJ,

See there http://regexlib.com/default.aspx
T> Hi
T>
T> I'd like to validate a string input as a phone number using a regex
T> matcher. This is the criteria:
T> * at least 10 numbers,
T> * only numeric and the following special characters should be
T> allowed:
T> '+' '-' '(' ')' and spaces
T> The closest I've been able to find is ^[-\d()\s]*$ :-(
T>
T> Thank you in advance,
T> tJ
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

Here's a sample
What I am expecting
"(123) 456-7890"
The Reg-Ex that validates if it what I am expecting
(("^\(?\d{3}\)?\s|-\d{3}-\d{4}$"))

You could base of from this, hope it helps.

Thanks
 

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