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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^\(?[\d]{3}\)?[\s-]?[\d]{3}[\s-]?[\d]{4}$
Description
This regular expression matches 10 digit US Phone numbers in different formats. Some examples are 1)area code in paranthesis. 2)space between different parts of the phone number. 3)no space between different parts of the number. 4)dashes between parts.
Matches
(573)8841878 | 573-884-1234 | 573 234 1256
Non-Matches
(573)(673)2345 | 573-12-2345
Author Rating: The rating for this expression. kode kode
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: Good regex matching for regular phone numbers
Name: Harish Reddy M
Date: 1/20/2017 10:48:14 AM
Comment:
Wow! It worked like gem for US,Indian and for phone numbers which contains 10 digits. Regards, Harish


Title: Parenthesis matching
Name: Gideon Engelberth
Date: 4/4/2005 10:58:43 AM
Comment:
Right now, your expression allows for one but not both of the parenthesis. This can be fixed one of two ways: ^(?<open>\()?[\d]{3}(?(open)\))?[\s-]?[\d]{3}[\s-]?[\d]{4}$ which uses groups to require a ")" if there is an "(" or ^(?:\(\d{3}\)|\d{3})?[\s-]?[\d]{3}[\s-]?[\d]{4}$ which uses alternation to require both or none


Title: Sr. Software Engineer
Name: Venkat
Date: 12/1/2004 1:28:12 PM
Comment:
It doesn't check for the open / close parenthesis.


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