|
Posted by Richard Levasseur on 10/23/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]
|