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 Pattern Title
Expression
^[^0-9]*(?:(\d)[^0-9]*){10}$
Description
Recently I've been forced to validate phone numbers in a variety of formats, with all sorts of whitespace, dashes, parenthesis, etc. I didn't want to hassel with matching all that junk, I just wanted the 10 numbers! So I wrote this expression which captures 10 digits in a string if there are exactly 10 digits. Anything else is allowed so long as there are 10 numbers. In .Net, You just loop through the Captures collection of Groups[1] of your Regex.Match object and concatenate the Capture.Value strings to get a simple, pure 10 digit phone number. ( myMatch.Groups[1].Captures )
Matches
1234567890 | 585-737-8899 | (324)blah225-foo2587
Non-Matches
1234567 | 12345678901
Author Rating: Not yet rated. Todd Moon
   Displaying page 1 of 1 pages; Items 1 to 1

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