Validate US Telephone Numbers: Fail Anyway?

Validate US Telephone Numbers: Fail Anyway?
0

#1

Tell us what’s happening:
Hey friends! Run this code and look at the output in the console. Despite me console logging the exact same code snippet as the one I’m using for the return:

validate.test(number);

I get the correct booleen, as asked for in the instructions during the console log, but it doesn’t let it pass. The second and fourth conditions in the algorithm instructions both return true as requested. What am I doing wrong?! Please help me figure this out and get back in the groove of things. I feel like I’ve fallen a little behind lately.

Your code so far

function telephoneCheck(str) {
  console.log(str);
  var number = str.replace(/\-/g,"");
  console.log("________________" + number);
  var validate = new RegExp(/1?\(?\d+\)?\d+/, "g");
  console.log(validate.test(number));
  return validate.test(number);
}



telephoneCheck("555-555-5555");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:

EDIT: found a solution. I’m still confused by this a little, but it seems I just need more practice with RegExp