Add phone number validator certification project
This commit is contained in:
parent
ce8e046407
commit
721ebf560f
1 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,32 @@
|
|||
function telephoneCheck(str) {
|
||||
const regex = /((^((\(\d{3}\))|(\d{3})))(\s?-?(\d{3}))(\s?-?\d{4})$)|(^1(((\s|-)\d{3})|(\s?-?\(\d{3}\)))(\s?-?\d{3}\s?-?\d{4}))/
|
||||
return regex.test(str);
|
||||
}
|
||||
|
||||
|
||||
// All of those should be true:
|
||||
let testsTrue = [
|
||||
telephoneCheck("555-555-5555"),
|
||||
telephoneCheck("(555)555-5555"),
|
||||
telephoneCheck("(555) 555-5555"),
|
||||
telephoneCheck("555 555 5555"),
|
||||
telephoneCheck("5555555555"),
|
||||
telephoneCheck("1 555 555 5555"),
|
||||
telephoneCheck("1 (555) 555-5555")
|
||||
]
|
||||
|
||||
// All of those should be false:
|
||||
let testsFalse = [
|
||||
telephoneCheck("(555-555-5555"),
|
||||
telephoneCheck("(555)5(55?)-5555"),
|
||||
telephoneCheck("11 555-555-5555"),
|
||||
telephoneCheck("10 (757) 622-7382"),
|
||||
telephoneCheck("5555555"),
|
||||
telephoneCheck("555-5555"),
|
||||
telephoneCheck("55555555"),
|
||||
telephoneCheck("27576227382")
|
||||
]
|
||||
|
||||
console.log("True: " + testsTrue);
|
||||
console.log("False: " + testsFalse);
|
||||
console.log("bla")
|
Reference in a new issue