JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Tell us what’s happening:

Describe your issue in detail here.
Can someone give a review why it’s not giving me a pass?

Your code so far

function telephoneCheck(str) {
const phoneRegex = /^(1\s?)?(\()?\d{3}(\))?[-\s]?\d{3}[-\s]?\d{4}$/;
  return phoneRegex.test(str);
}

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


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

You are getting three errors back telling you that your pattern is returning true when it should return false. Do you know which part of your regex pattern is causing this? Look at what all three of those telephone numbers have in common.

The thing is I tried looking at the patterns but it still ends up returning true

What weird thing do all three of the phone numbers have in common? They aren’t supposed to pass, so they all have something wrong with them. What is it?

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