Tell us what’s happening:
So there are 3 tests that I couldn’t pass:
- telephoneCheck(“1 555)555-5555”) should return false.
- telephoneCheck(“555)-555-5555”) should return false.
- telephoneCheck(“(555-555-5555”) should return false.
In both instances in my regex, I made sure that I added “?” at the end for “(” and “)” to match zero or one instance of the open and close parentheses. But somehow, I couldn’t pass the 3 tests above.
**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 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Telephone Number Validator
Link to the challenge: