I’m horrible at regular expressions, but I’m giving this challenge my best effort. I cant figure out for the life of me why this isn’t working. The way it seems to me is this current one should check if there is 0 or 1 "1"s at the beginning, and then check to see if it is followed by ten digits. there is filter at the beginning that gets rid of all not digit charaters and whitespace. I’ve been slowly logging through the failing test cases to try and debug, but there are sooo many to go through, I’m hoping someone can point out the flaw in my regex.
Your code so far
function telephoneCheck(str) {
var str = str.replace(/\D/g,"");
var regEx = /^(1)?\d{10}/;
console.log(str);
var test = regEx.test(str);
return test = regEx.test(str);
console.log(test);
}
telephoneCheck("1 555 555 5555");
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS aarch64 11151.29.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.49 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