Tell us what’s happening:
My code is working for every scenario except for one case starting with -1. Do you have any idea why only this doesn’t work? If it starts with any number other than 1, it is supposed to fail. It works with other tests starting with 2,3,4.
Your code so far
function telephoneCheck(str) {
// Good luck!
return /^1{0,1}\d{10}$|^1{0,1}\(\d{3}\)\d{7}$/.test(str.replace(/[^0-9()]/gi, ""));
}
console.log(telephoneCheck("-1 (555)555-5555"));
console.log(telephoneCheck("2 (555)555-5555"));
console.log(telephoneCheck("3 (555)555-5555"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator