Telephone Number Validator

Tell us what’s happening:

The problem is that it matches anything even with any number other than 1, a fix for that please? I tried for 3 hours for a solution but regex is not my strong side.

Your code so far

function telephoneCheck(str) {
return /(1\s)?(\([0-9]{3}\)|[0-9]{3})(\s|-)?[0-9]{3}(-|\s)?[0-9]{4}/g.test(str);


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:

Nevermind. I solved it.

This is my solution.

function telephoneCheck(str) {
  // Good luck!
  return /^(1\s|1)?(\(\d{3}\)|\d{3})(-|\s)?\d{3}(-|\s)?\d{4}$/.test(str);


lol it took me 2 days and more than 20 lines of code with if statements and4 regex variables
to solve this challenge
and when i passed i came to the forums and found your one line solution
nice work maybe i need to practise regex more often and make deeper understanding of it

1 Like

your solution gave me depression…