Telephone Number Validator problems

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}/; 
  var test =  regEx.test(str);
  return test =  regEx.test(str);

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:

1 Like


Visualize your regular expression on regexr to see where you are running into problems. This is my go-to tool whenever I’m stuck on a regex.

Hope this helps some.

1 Like

También es mi pesadilla las expresiones regulares.