RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$
Description
US Phone Number: This regular expression for US phone numbers conforms to NANP A-digit and D-digit requirments (ANN-DNN-NNNN). Area Codes 001-199 are not permitted; Central Office Codes 001-199 are not permitted. Format validation accepts 10-digits without delimiters, optional parens on area code, and optional spaces or dashes between area code, central office code and station code. Acceptable formats include 2225551212, 222 555 1212, 222-555-1212, (222) 555 1212, (222) 555-1212, etc. You can add/remove formatting options to meet your needs.
Matches
5305551212 | (530) 555-1212 | 530-555-1212
Non-Matches
0010011212 | 1991991212 | 123) not-good
Author Rating: The rating for this expression. Don Johnston
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: IT GUY
Name: Modaresi
Date: 4/7/2014 11:58:48 PM
Comment:
Exactly what I was looking for. Best out there in my opinion.


Title: IT GUY
Name: Modaresi
Date: 4/7/2014 11:54:39 PM
Comment:
Exactly what I was looking for. Best out there in my opinion.


Title: IT GUY
Name: Modaresi
Date: 4/7/2014 11:54:31 PM
Comment:
Exactly what I was looking for. Best out there in my opinion.


Title: Small changes to best NANP matcher
Name: Gregory Krohne
Date: 8/2/2007 10:14:48 AM
Comment:
This is the best NANP pattern so far, IMHO. The NANP specifies that the second digit of the area code digit can only be [0-8]. I propose allowing a period as a separator, and using word boundary to find the end of the phone number. There's no need to place "|" between the separators; they're just single characters, and they can go into a character class bracket.


Title: Perfect!
Name: Warren
Date: 5/2/2007 10:40:54 AM
Comment:
This was what I was trying to do for a day and could not do. Please tell me what the ":" character does. I cannot find any documentation on it. Thanks, Warren


Title: Top Notch
Name: Kevin
Date: 3/15/2005 1:22:17 PM
Comment:
Best on the site for basic validation. Proper but not too constraining on - space mixtures.


Title: Very Good!!!
Name: Vinny Vinn
Date: 7/15/2004 10:40:51 AM
Comment:
Great!! There are not to many Regular Expression that match 4323456789 without - () etc.. Thanks


Title: Thanks
Name: DJohnston
Date: 4/21/2004 12:42:01 PM
Comment:
Good tip to add the dot separator. Thanks.


Title: Programmer
Name: logspirit
Date: 4/18/2004 10:10:12 PM
Comment:
To allow for . as separator, which is becoming more popular ^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?|\.?))[2-9]\d{2}[- \.]?\d{4}$ It now matches 345.678.9012 and (345) 678.9012 Not sure what the problem was for the apparent test (203 768-9876 on the original... It (properly) does NOT match.


Title: Matches this
Name: Vasanth Vemula
Date: 4/2/2004 11:40:07 AM
Comment:
(203 768-9876


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials