Posted By

martinkas on 03/13/08


Tagged

regex phone us extension


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mikegreen
jeremyhcobb
jadb
Tyster


US Phone Number with extension, flexible


 / Published in: Regular Expression
 

  1. ^((1|+1)?( |-|.)?)?((?[0-9]{3})?|[0-9]{3})( |-|.)?([a-zA-Z0-9]{3}( |-|.)?[a-zA-Z0-9]{4})[ ]*(( |x|ext|ext.|extension|Ext|Ext.|Extension|#){1}[ ]?([0-9]){1,7}){0,1}$
  2.  
  3. matched
  4. (223)456 7891 x 123
  5. (223)456 7891 ext 123
  6. (223)456 7891 ext. 123
  7. (223)456 7891 Ext 123
  8. (223)456 7891 Ext. 123
  9. (910)456-8970 x12
  10. (910)456-8970 #12
  11. (910)456-8970 extension12456
  12. (910)456-8970 Extension 12456
  13. 234.445.6789
  14. 987 765-8765
  15. 1 (453) 876 9876
  16. +1 (453) 876 9876
  17. (800)ABCDEFG
  18. (800) ABC-1234
  19.  
  20. not matched
  21. 2 (453) 876 9876
  22. (4534) 876 9876
  23. (453) 8764 9876
  24. (453) 876 98769

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Scooter on May 24, 2008

( |-|.)? can be achieved more simply with [- .]?

Area codes cannot begin with a 0 or 1; you might want to consider expanding your [0-9]{3} to [2-9]{1}[0-9]{2}

You need to login to post a comment.