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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[ ])|(?:(?<3>[-])|(?<4>[ ])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode)(?:(?(1)(?(2)[- ]|[-]?))|(?(3)[-])|(?(4)[- ]))|[- ]?)(?<Suffix>\d{4})$
Description
Regular expression for validating US telephone numbers with OPTIONAL area code. Matches various permutations of formatting characters (parenthesis, space, dash). Parses the telephone number area code, prefix, and suffix to named groups to facilitate program manipulation. Area code is optional and can optionally be enclosed in parentheses. Rejects area codes that begin with 0 or 1 and prefixes that begin with 0. Rejects all telephone numbers that do not match on exactly 7 digits, or on exactly 10 digits with the optional area code, not counting the formatting characters.
Matches
333-4444 | 222 333 4444 | (222) 333-4444
Non-Matches
222333 4444 | 222-333 4444 | (222)-333 4444
Author Rating: The rating for this expression. Jerry Schmersahl
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: Syntax Error
Name: Lucy
Date: 1/20/2005 1:09:02 PM
Comment:
I received a javascript error while running this validation. The error says Invalid Regular Expression Syntax. Please advice. You can reach me at ngbedong@yahoo.com Thanks


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