note 55208 added to ref.regex
| From: | trucex | Date: | Wed, 27 Jul 2005 18:00:44 +0000 |
| Subject: | note 55208 added to ref.regex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92572@lists.php.net to get a copy of this message | ||
I was having a ton of issues with other people's phone number validation expressions, so I made
my own. It works with most US phone numbers, including those with extentions. Format matches any of
the following formats:
5551234567
555 1234567
555 123 4567
555 123-4567
555-1234567
555-123-4567
555123-4567
(555)1234567
(555)123 4567
(555)123-4567
(555) 1234567
(555) 123-4567
(555) 123 4567
And any of the following extentions can be added with or without a space between them and the
number:
x123
x.123
x. 123
x 123
ext.123
ext. 123
ext 123
ext123
Extentions support between 1 and 5 digits.
Here is the expression:
$regex = '^[(]?[2-9]{1}[0-9]{2}[) -]{0,2}' . '[0-9]{3}[- ]?' . '[0-9]{4}[
]?' . '((x|ext)[.]?[ ]?[0-9]{1,5})?$';
Enjoy!
----
Manual Page -- http://www.php.net/manual/en/ref.regex.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55208
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55208&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55208&report=yes
Search -- http://master.php.net/manage/user-notes.php