JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Telephone Number Validator

Hello, I am trying to do Telephone Number Validator project but i think i got stuck and need help.

So far i am using this regular expression for my validator and it goes well with all the test cases but it does not ensure the opening and closing parenthesis.
For instance the test cases with single parenthises (Opening or closing) are still returning true.
I tried to make the whole block optional but it’s not very effective.
Can you please contribute to my project …
thanks

let reGex = /^(\+?1\s?)?[\(]?[0-9]{3}[\)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;

Your browser information:

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

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

it’s yours to do, as it’s a final project

A suggestion, if you want to do with a single regex code, you need to use a couple more regex features. like, do you remember about lookaheads and lookbehinds?

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