A comprehensive regex for phone number validation -


i'm trying put 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 answer current attempt, i'm hoping has better 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 use 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 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -