Tell us what’s happening:
I’m trying to create just one regexp to pass all test but I need a little help on how to make the regular expression validate the two numbers between parentheses and when it starts with 1 and then space and then parenthesis
Your code so far
function telephoneCheck(str) {
// Good luck!
let patter = /^1?(\d{3})[(\d{3})]?[-/s]*(\d{3})[-/s]*(\d{4})$/g
return patter.test(str)
}
console.clear()
console.log(telephoneCheck("555-555-5555"));
console.log(telephoneCheck('555 555 5555'))
console.log(telephoneCheck("(555)555-5555"));
console.log(telephoneCheck("1 (555) 555-5555"));
console.log(telephoneCheck("5555555555"));
console.log(telephoneCheck("555)-555-5555"))
console.log(telephoneCheck("1 555 555 5555"));
//console.log(telephoneCheck("8oo-six427676;laskdjf"))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 YaBrowser/20.2.2.177 Yowser/2.5 Safari/537.36
.
Challenge: Telephone Number Validator
Link to the challenge: