Skip to content

Instantly share code, notes, and snippets.

@denniszhao
Created August 15, 2014 20:01
Show Gist options
  • Save denniszhao/7b324b8f8900589ff68f to your computer and use it in GitHub Desktop.
Save denniszhao/7b324b8f8900589ff68f to your computer and use it in GitHub Desktop.
function isValidUSPhoneNum(number) {
// Matches valid US numbers of the form
// xxx (whitespace or -) xxx (whitespace or -) xxxx
var USPhoneNumRegex = /^(?:\([2-9][0-9]{2}\)(?:[\s]*|[-])|[2-9][0-9]{2}(?:[\s]*|[-]))[0-9]{3}(?:[\s]*|[-])[0-9]{4}$/;
// booleanize bitch
return !!number.match(USPhoneNumRegex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment