Telephone Number Validator question

Tell us what’s happening:

I’m trying to complete the telephone number validator challenge this is what I have so far

Your code so far

function telephoneCheck(str) {
var isValid = false;
  //only allow numbers, dashes, dots parentheses, and spaces
  if (/^[\d-\s.]+$/ig.test(str)) { 
    //replace all non-numbers with an empty string
    var justNumbers = str.replace(/\D/g, '');
    var count = justNumbers.length;
    if(count === 10 || (count === 11 && justNumbers[0] === "1") ){
      isValid = true;
  console.log(isValid, str);
  return isValid;



the tests
telephoneCheck("1 (555) 555-5555")
telephoneCheck("(555)555-5555") should return true.
telephoneCheck("1(555)555-5555") should return true.

aren’t passing though, what should I add? Thanks.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

Link to the challenge:

I can’t do any debugging now but maybe check with this tool with the tests you are missing where your code doesn’t do what it should

And remove the g flag for the test method, that does give unexpected results if you don’t know what it does

The explanation in the examples section of this page: