Displaying page
of
pages;
Items to
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
of
pages;
Items to