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

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 1
Title Test Details US Phone with/without Extension (.NET)
Expression
\(?(\d{3})(?:\)*|\)\s*-*|\.*|\s*|/*|)(\d{3})(?:\)*|-*|\.*|\s*|/*|)(\d{4})(?:\s?|,\s?)
Description
Fairly universal regex for matching any US Phone number in .net. It basically matches the 10 digit phone number using the common US patterns, and allows for any text after the fact. I use it with the .replace method and pull out "$1$2$3" to get the pure 10-digit phone number, and anything after that is just stored as additional text. this additional text could be an extension, daytime information, hours, etc.
Matches
9405551234, (940) 555-1234, 940.555.1234, 940-555-1234, 940-555-1234 x5000, 940-555-1234, ext. 5000, 940-555-1234 8-5pm
Non-Matches
94055512345, 9401-546-5468, or any other non-10-digit, non-standard pattern
Author Rating: Not yet rated. Jorin Slaybaugh
   Displaying page 1 of 1 pages; Items 1 to 1

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