But it’s returning true…
Your code so far
function telephoneCheck(str) {
let regex = /(^\d\d\d-\d\d\d-\d\d\d\d$)|(^\(\d\d\d\)\d\d\d-\d\d\d\d$)|(^\(\d\d\d\)\d\d\d-\d\d\d\d$)|(^\d\d\d \d\d\d \d\d\d\d$)|(^\d\d\d\d\d\d\d\d\d\d$)|(^1 \d\d\d \d\d\d \d\d\d\d$)|(^1 \(\d\d\d\) \d\d\d-\d\d\d\d$)|(^1 \d\d\d-\d\d\d-\d\d\d\d$)|(^1\(\d\d\d\)\d\d\d-\d\d\d\d$)/g;
console.log(regex.test(str));
return regex.test(str);
}
telephoneCheck("1 555-555-5555");
telephoneCheck("1 (555) 555-5555");
telephoneCheck("5555555555");
telephoneCheck("555-555-5555");
telephoneCheck("(555)555-5555");
telephoneCheck("1(555)555-5555");
telephoneCheck("1 555 555 5555");
telephoneCheck("1 456 789 4444");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Telephone Number Validator
Link to the challenge: