Issue with phone number validation

Hello, I’ve been working on the 4th project on the JavaScript and Algorithm course for the past three days (Telephone validator). Seen a lot of solutions online, but I really want to go ahead with the algorithm I’m currently using.
I’m trying to solve it using the if…else method, but it only validates the ones that return false. I don’t know where this is coming from.

My code so far


function telephoneCheck(str) {
  
  let tenDigits= str.match(/^\d{10}$/);
  let elevenDigits = str.match(/^\d{11}$/);
  let startsWithOne=str.match(/^[1]$/);
  let permittedChars=str.match(/^[\\d() -]+$/);
 if(tenDigits && permittedChars){
   return true;
 }else if(elevenDigits && startsWithOne && permittedChars){
   return true
 }else
 return false;
  
}
  
  telephoneCheck("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/75.0.3731.0 Safari/537.36.

Challenge: Telephone Number Validator

Link to the challenge:

Welcome, amarachukwu.

To help you debug, I would add this line to before your if statement:

console.log(tenDigits, permittedChars, elevenDigits, startsWithOne, permittedChars);

This will not solve your issues, but I think regex.test(string) is more of what you want, as opposed to string.match(regex). Look into the test method.

Now, why not combine the if and else if, seeing as they both return true?

Thanks Sky. I’ve done this, its returning NULL
I’m currently looking at my regex again, I think there’s an error in my logic