Created
April 2, 2022 11:22
-
-
Save kostikovmu/067135f2b2a8d0bb0685f310db7c80ff to your computer and use it in GitHub Desktop.
us phone validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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