Tell us what’s happening:
I’m having trouble getting the strings "1 555)555-5555"
and "(555-555-5555"
to return false
. The issue is with the single parenthesis either to the left or right of the area code. I’ve spent a few hours researching on how to change my regex. After reading through the MDN cheatsheet for regular expressions as well as Stack Overflow, I’ve tried using a lookahead assertion around the area code to pass the parenthesis only if its matching closer/opener is included, but that just made more of the tests not pass.
Any tips or hints to help point me in the right direction are greatly appreciated.
**Your code so far**
function telephoneCheck(str) {
let regExp = /^1*\s*\(*\d{3}-*\s*\)*\s*\d{3}-*\s*\d{4}$/;
if (str.match(regExp)) {
return true;
} else {
return false;
}
}
console.log(telephoneCheck("(555-555-5555"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0
Challenge: Telephone Number Validator
Link to the challenge: