Skip to content

Instantly share code, notes, and snippets.

@jefferyrdavis
Last active May 16, 2019 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefferyrdavis/5992287 to your computer and use it in GitHub Desktop.
Save jefferyrdavis/5992287 to your computer and use it in GitHub Desktop.
Snippit: PHP: Validate U.S. phone Number
<?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