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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?:(?<Contry>\d{1,1})(?<5>[- ]?)?)?(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[ ])|(?:(?<3>[-])|(?<4>[ ])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode)(?:(?(1)(?(2)[- ]|[-]?))|(?(3)[-])|(?(4)[- ]))|[- ]?)(?<Suffix>\d{4})(?:[ ]?[#xXeE]?(?<Ext>\d{2,4}))?$
Description
Regular expression for validating US and CANADA telephone numbers with OPTIONAL contry code, OPTIONAL area code, and OPTIONAL extension. Matches various permutations of formatting characters (parenthesis, space, dash). Parses the telephone number contry code, area code, prefix, suffix, and extension ...
Matches
1-(222) 333-4444 | 1 (222) 333-4444 | 12223334444
Non-Matches
1- (222) 333 4444 | 1 (222) 333-4444 | 1 2223334444
Author Rating: The rating for this expression. Marc Robitaille
Source Jerry Schmersahl
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: Sorry!
Name: Angelito
Date: 8/20/2008 3:12:53 PM
Comment:
I just meant to post once. This is what happen when you refresh your browser to see your post.


Title: How to install?
Name: Angelito
Date: 8/20/2008 3:08:59 PM
Comment:
Could some one guide me how to set this expression to test an input telephone field. Thank you!


Title: How to install?
Name: Angelito
Date: 8/20/2008 3:08:40 PM
Comment:
Could some one guide me how to set this expression to test an input telephone field. Thank you!


Title: How to install?
Name: Angelito
Date: 8/20/2008 3:08:30 PM
Comment:
Could some one guide me how to set this expression to test an input telephone field. Thank you!


Title: Remarkable!
Name: Josh Withrow - LuckyDogDigital.com
Date: 8/12/2007 10:41:41 PM
Comment:
Great job on this! I found this extremely handy!


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