Skip to content

Instantly share code, notes, and snippets.

@iCaspar
Created December 11, 2018 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iCaspar/923b20c9cd8121a525d63cea809d1b0c to your computer and use it in GitHub Desktop.
Save iCaspar/923b20c9cd8121a525d63cea809d1b0c to your computer and use it in GitHub Desktop.
Function to validate a US phone number
function telephoneCheck(str) {
const usPhoneRegex = /^(?:1\s?)?(?:\d{3}|\(\d{3}\))[\s|-]?\d{3}[\s|-]?\d{4}$/
return usPhoneRegex.test(str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment