Skip to content

Instantly share code, notes, and snippets.

@denniszhao
Created August 15, 2014 19:56
Show Gist options
  • Save denniszhao/21c24ee200291fb7a6e6 to your computer and use it in GitHub Desktop.
Save denniszhao/21c24ee200291fb7a6e6 to your computer and use it in GitHub Desktop.
Return true if valid phone number
function isValidUSPhoneNum(number) {
var USPhoneNumRegex = /^(?:\([2-9]{3}\)(?:[\s]*|[-])|[2-9]{3}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/;
// booleanize
return !!number.match(USPhoneNumRegex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment