JavaScript Algorithms and Data Structures Projects - Telephone Number Validator

Tell us what’s happening:
Describe your issue in detail here.
i’ve got problems with the digit 1 and the “()”
Your code so far

function telephoneCheck(str) {
  let regex = /^1?\s?(\d{3}|\(d{3}\))-?\s?\d{3}-?\s?\d{4}$/gm
  return regex.test(str)
}

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

Your browser information:

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

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

Link to the challenge:

have you tried an online regex tester?

they are useful so you can figure out what each part of the regex is doing and test them incrementally

I’ll try it. thank you, bro

1 Like

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