Title |
Test
Find
Pattern Title
|
Expression |
^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$ |
Description |
U. S. or Canadian telephone number regular expression. <BR>
<BR>
// # Checks phone numbers for validity <BR>
// [01]? # optional '0', or '1' <BR>
// [- .]? # optional separator is either a dash, a space, or a period. <BR>
// \(? # optional parentheses <BR>
// [2-9] # first # of the area code must not be a '0' or '1' <BR>
// \d{2} # next 2 digits of area code can be 0-9 <BR>
// \)? # optional parentheses <BR>
// [- .]? # optional separator is either a dash, a space, or a period. <BR>
// \d{3} # 3-digit prefix <BR>
// [- .]? # optional separator is either a dash, a space, or a period. <BR>
// \d{4} # 4-digit station number <BR>
|
Matches |
18008793262 | 800-879-3262 | 0-800.879.3262 |
Non-Matches |
879 3262 | 077 879 3262 | 879-3262 |
Author |
Rating:
Not yet rated.
W. D.
|
Source |
http://www.US-Webmasters.com/ |
Your Rating |
|
Title: Great
Name: Delmar Reid
Date: 5/30/2006 10:40:40 AM
Comment:
This is very useful, thanks!
Title: Variation with optional Extension
Name: Bob C
Date: 8/9/2005 4:47:38 PM
Comment:
This version adds an optional extension in the form xnnn
^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}([ ][x]\d\d*?)?$
Title: Thanks
Name: Bob C
Date: 8/9/2005 11:06:06 AM
Comment:
This site is a life-saver!!! Highly recommended. I'll pass it on.
Title: Lookahead Assertion Might Be Needed
Name: W. D. (http://www.US-Webmasters.com/)
Date: 2/18/2004 12:40:01 AM
Comment:
Yep. You are correct. I just created this the way
it is because I wanted the user to type in a valid
phone number with area code. So, even though
211) 111-1111 looks a little goofy, it has all the
digits there. I am writing a routine that strips
out all but the numbers and then formats it like
this:
211-111-1111
--
Title: Lookahead Assertion Might Be Needed
Name: J$
Date: 2/17/2004 10:31:56 PM
Comment:
That regex matches the following:
211) 111-1111
Title: Lookahead Assertion Might Be Needed
Name: J$
Date: 2/17/2004 10:31:56 PM
Comment:
That regex matches the following:
211) 111-1111