Telephone Number Validator return false

Tell us what’s happening:

I don’t get why is my function returning “false” in that case.
Your code so far


function telephoneCheck(str) {
var unique = str.replace(/[^\w\s]/gi, "").replace(/\s/g,'');
var dtl = str.split("")
var result = unique.split("");
if((dtl.indexOf("(") == -1 && dtl.indexOf(")") == -1) 
|| (dtl.indexOf("(") == 1 && dtl.indexOf(")") == 1)) {
 if((result.length == 10 && result[0] == 5)
 || (result.length == 11 && result[0] == 1)) {
  return true;
}
}
  return false;
}

console.log(telephoneCheck("1(555)555-5555"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36.

Challenge: Telephone Number Validator

Link to the challenge:

Hi. I think you’re suppose to do it with a regex.

1 Like

But why does this function not return true?

this evaluates to false - you can’t have two different characters in same position

1 Like