Created
August 20, 2012 16:01
-
-
Save cam-gists/3405375 to your computer and use it in GitHub Desktop.
PHP: US Phone # validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // simple phone number | |
| $phone_number_as_integer = preg_replace("/[^0-9]/", "", $phone); | |
| if( !preg_match("/^()?[0-9]{3}[0-9]{3}[0-9]{4}$/i", $phone_number_as_integer) ) | |
| { | |
| $phone_error = 'Please enter a valid phone number.'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment