JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Tell us what’s happening:

Describe your issue in detail here.
I’ve been stuck with this question for the last 3 days and I don’t know nothing about regex does anyone know about regex?

Your code so far

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

console.log(telephoneCheck("800-692-7753"));
console.log(telephoneCheck("800six427676; laskdjf"));

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

I find the website https://regex101.com/ very helpful constructing, testing and learning about regex

1 Like

Do i just type my question?

Hey, weren’t we already discussing this in another post? It’s best to not create duplicates for the same issue.

Go back to the original one and look at my last reply. I asked you to tell me what the three phone numbers that weren’t passing had in common. You’ll need to figure that out before you can figure out how to fix your pattern.

Did you complete the Regular Expressions course? It seems like you know something about regular expressions because you were able to create an expression that is close, it just needs a few tweaks. But you can’t do that until you understand what is wrong.

The 3 phone number was
(“555-555-5555”);
(“1 555)-555-5555”);
(“5555555555”);
that didn’t let me pass

The code you pasted in at the top of the page isn’t valid. It has syntax errors and thus won’t run. The code in your original post was much better and was fairly close. Again, I would go back to your original post and use that code and answer my question.

The one I had last night?

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