Why is this not a valid number (telephoneCheck("55 55-55-555-5"));

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function telephoneCheck(str) {
 if (str.indexOf("(") === -1 && str.indexOf(")") > -1){
   return false
 }

 if (str.indexOf(")") - str.indexOf("(") >= 5){
   return false;
 }
 if (str[0] === "-") return false;
let polishedString = str.replace(/\-| /g , "");
console.log(polishedString)

if (polishedString.indexOf("(") < polishedString.indexOf(")")) {
 polishedString = polishedString.replace(/\(|\)/g, "")
 console.log(polishedString)
 
}
console.log(polishedString)

 if (polishedString.length === 10) {
 return true;
}else if (polishedString.length === 11 && polishedString[0] === "1") {
 return true;
}

 return false;
}

console.log(telephoneCheck("55 55-55-555-5"));
   **Your browser information:**

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

Challenge: Telephone Number Validator

Link to the challenge:

it does not have the 3-3-4 pattern of a valid number format

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function telephoneCheck(str) {
 if (str.indexOf("(") === -1 && str.indexOf(")") > -1){
   return false
 }

 if (str.indexOf(")") - str.indexOf("(") >= 5){
   return false;
 }
 if (str[0] === "-") return false;
let polishedString = str.replace(/\-| /g , "");
//console.log(polishedString.length)

if (polishedString.indexOf("(") < polishedString.indexOf(")")) {
 polishedString = polishedString.replace(/\(|\)/g, "")
 console.log(polishedString)
 
}
console.log(polishedString.length)

if (polishedString.length === 10) {
 return true;
}else if (polishedString.length === 11 && polishedString[0] === "1") {
 return true;
}

 return false;
}

console.log(telephoneCheck("55 55-55-555-5"));
   **Your browser information:**

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

Challenge: Telephone Number Validator

Link to the challenge:

So how can I add that condition in code.

I think you need to think a bit more on how to verify a number
the lines I quoted is where you evaluate the dashes and then eliminate them, but you are checking only for the presence at the beginning

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.