Telephone Number Validator: almost and need some suggestions

I have used regex with an if else statement and most of the tests are passing.

There are a few more tests to pass, and the one I’m trying to code in for is: 27576227382, along with a few others to recognize return false. When I try to code in a str.match() to recognize any number greater than 2 followed by digits, I’m not getting anything using this: str.match(/^(2(?=\d*)) Shouldn’t this recognize the number 2 followed by digits when added as a new if else statement? I haven’t placed this in the code below yet but when I add it in my tests, the 27576227382 does not pass the test.

Link to Project: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator/

Current Code:

function telephoneCheck(str) {

if ( str.match(/^\d/) && str.match(!/^1/) || str.match(/^\d/) && str.match(/^(\d(?=\d{9}))/) || str.match(/^\(/) || str.match(/^(\d(?=\d{2}\-))/) ) {

  return true;

} else if ( str.match(/^(1(?=\s\d{3}\s))/) || str.match(/^(1(?=\s\d{3}\-))/) || str.match(/^(1(?=\s[\(]\d{3}[\)]\s))/) || str.match(/^(1(?=[\(]\d{3}[\)]\d))/)  ) {
  
  return true;
} 
 return false;

}

The intent of the challenge is to create one regex that tests all the phone numbers that the test tests for. It can be done with one regex. Look into that rather than the if else statement. I’m not saying it can’t be done with your approach but it is shorter and easier to read with one regex.

I see what you mean. Thanks for the tip!