Tell us what’s happening:
I’ll need some help with this, and I’m trying to clear the three tests,
“telephoneCheck("1 555)555-5555") should return false . telephoneCheck("555)-555-5555") should return false. telephoneCheck("(555-555-5555") should return false.”
Can anyone assist me with this?
Your code so far
function telephoneCheck(str) {
let telRegex = /^1(\s)?\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$|^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
return telRegex.test(str);
}
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/106.0.0.0 Safari/537.36 Edg/106.0.1370.34
Challenge: JavaScript Algorithms and Data Structures Projects - Telephone Number Validator
Consider that the \(?and \)? around the first part of digits will accept patterns with - no parenthesis, single parenthesis (on one of the sides) and two parenthesis (on both sides).
The tool?
I just put your pattern in the top field (the regular expression field)
And then I pasted the test strings in the box below.
And for eg I found the area of the pattern that was matching the ) for eg. Then from there you have to decide what to do. For eg maybe you want to have a conditional pattern to match the left ( bracket first and if found match the right.)
The tool is there to help but you don’t have to use it.