Skip to content

Instantly share code, notes, and snippets.

@kostikovmu
Created April 2, 2022 11:22
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 kostikovmu/067135f2b2a8d0bb0685f310db7c80ff to your computer and use it in GitHub Desktop.
Save kostikovmu/067135f2b2a8d0bb0685f310db7c80ff to your computer and use it in GitHub Desktop.
us phone validator
function telephoneCheck(str) {
const phoneRegxep = /^((\(\d{3}\))|((1\s|1)\(\d{3}\))|(\d{3})|(1\s\d{3}))(\s|-|)(\d{3})(\s|-)(\d{4})/
const d10 = /^\d{10}$/
return phoneRegxep.test(str) || d10.test(str);
}
// phone formats
// 555-555-5555
// (555)555-5555
// (555) 555-5555
// 555 555 5555
// 5555555555
// 1 555 555 5555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment