Tell us what’s happening:
Hi, I am trying to do the JavaScript certification. I am currently on the the Telephone Number Validator challenge. After testing my regular expression on regex101.com, I passed a few of the tests from the challenge and moved the regex over to FreeCodeCamp to run the test.
In my code, I included console.log() for easy debugging to just change the argument of telephoneCheck() and avoid running the tests every time. The problem is that when I run the tests, I get a whole bunch that do not pass. However, when I input those same strings as the function’s argument in the editor, the console prints “true”. Those tests also pass on regex101. Is there a problem with the tests that have been set up for this challenge?
**Your code so far**
function telephoneCheck(str) {
const regex = /^1?\s?(\((?=\d{3}\)))?\d{3}((?<=\(\d{3})\)|-)?\s?\d{3}(\s|-)?\d{4}$/gi;
console.log(regex.test(str));
return regex.test(str);
}
telephoneCheck("1 555 555 5555");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36
Challenge: Telephone Number Validator
Link to the challenge: