JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Tell us what’s happening:
So there are 3 tests that I couldn’t pass:

  1. telephoneCheck(“1 555)555-5555”) should return false.
  2. telephoneCheck(“555)-555-5555”) should return false.
  3. telephoneCheck(“(555-555-5555”) should return false.

In both instances in my regex, I made sure that I added “?” at the end for “(” and “)” to match zero or one instance of the open and close parentheses. But somehow, I couldn’t pass the 3 tests above.

  **Your code so far**
function telephoneCheck(str) {
let telRegex = /^1(\s)?\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$|^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;

return telRegex.test(str);
}

telephoneCheck("555-555-5555");
  **Your browser information:**

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

Challenge: JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Link to the challenge:

It looks like your regex isn’t accounting for the fact that the ()s must come in pairs.

I’m sorry, but can you be more specific?

All of these test cases are when you have a different number of ) and (