You are here: Re: US phone number validation « PHP Programming Language « IT news, forums, messages
Re: US phone number validation

Posted by Richard Levasseur on 10/20/26 11:44

^(\D*)?(\d{3})(\D*)?(\d{3})(\D*)?(\d{4})$

if my regex memory serves correctly:
That will match xYYYxYYYxYYYY, where each x is a non-digit and is
optional, and Y is a digit. Group 2, 4, and 6 are the area code,
prefix, and suffix, respectively.

1234567890 - match
(123) 456-7890 - match
A123BCD4567890 - match
123-456-7890 - match

Another option is to strip all non-digits and see if its 10 characters
long:
regex: \D, with the global modifier on (preg_replace_all i think)

Store phone numbers as strings with all non-digits stripped out, then
display them how you like.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация