Hello everybody , i need some help to pass the telephoneCheck test .
now everything is going alright except for this part of the regex:
(?:\)(?<=\(\d{3}))
it’s a positive lookbehind (after a research i found out that it’s not supported here ) , so is there an alternative for it ? that’s the full code thanks for your help .
function telephoneCheck(str) {
// Good luck!
return str.match(/(?:1 )?(?:\((?=\d{3}\)))\d{3}(?:\)(?<=\(\d{3}))[- ]?\d{3}[- ]?\d{4}/g);
}
console.log(telephoneCheck("1 (555)-555-5555"));
you see … the problem is not in the lookahead it’s in the lookbehind
well i guess i found the solution LOL , i don’t even need a lookbehind regex , all i had to do is match the part where the problem is only if it is formatted like this :
(xxx) or xxx where x is a number between 0 to 9 .
here’s the full code :
function telephoneCheck(str) {
// Good luck!
return /^1? ?(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}$/.test(str);
}
console.log(telephoneCheck("1 (555)-555-5555"));
alright , sorry about that , i got carried by the joy of finding the answer