Last active
May 16, 2019 06:48
-
-
Save jefferyrdavis/5992287 to your computer and use it in GitHub Desktop.
Snippit: PHP: Validate U.S. phone Number
This file contains 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 | |
/*Validates if $phone is a valid U.S. phone number in the 202-555-1234 format. | |
Note that the first didgit cannot be a 1 as no area code in the U.S. starts with a 1. | |
*/ | |
function validatePhoneNo($phone) { | |
if(preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone)) | |
return true; | |
else | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment