Tuesday, 15 May 2012

A comprehensive regex for phone number validation -



A comprehensive regex for phone number validation -

i'm trying set comprehensive regex validate phone numbers. ideally handle international formats, must handle formats, including following:

1-234-567-8901 1-234-567-8901 x1234 1-234-567-8901 ext1234 1 (234) 567-8901 1.234.567.8901 1/234/567/8901 12345678901

i'll reply current attempt, i'm hoping has improve and/or more elegant.

better option... strip non-digit characters on input (except 'x' , leading '+' signs), taking care because of british tendency write numbers in non-standard form +44 (0) ... when asked utilize international prefix (in specific case, should discard (0) entirely).

then, end values like:

12345678901 12345678901x1234 345678901x1234 12344678901 12345678901 12345678901 12345678901 +4112345678 +441234567890

then when display, reformat hearts content. e.g.

1 (234) 567-8901 1 (234) 567-8901 x1234

regex validation phone-number

No comments:

Post a Comment