Tell us what’s happening:
I am failing 3 tests on the telephone number validation. They are for not having matching paranthesis. To solve this I tried a look ahead to say that if there is a lead parenthesis it should be followed by 3 digits and another closing parenthesis. It tests as valid code that doesn’t cause errors, but it still fails the same tests. I researched and looked at the hints, but I didn’t see anything using a look ahead. I do understand how they solved it with OR type logic, but I would like to know if it is possible with a lookahead. So,
- Is my syntax correct for the idea I’m trying to test?
- Can you even test optional characters as being followed by a lookahead or can I only search parenthesis followed by the lookahead where the first parenthesis is a must (not optional)? … Can I write if I have a parenthesis it should be followed by 3 digits and a closing parenthesis? or Can I only write I want a parenthesis followed by 3 digits and a closing parenthesis… /)(?=[\d{3})])? …assuming the lookahead is correct
I have also written the same code without brackets, and gotten the same results. At least I think so. Been a long day and it’s 2:30am…
Your code so far
function telephoneCheck(str) {
if (str.match(/^1?\s?\(?(?=[\d{3}\)])\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$/)){
return true;
}else {
return false;
}
}
telephoneCheck("555-555-5555");
Thanks for any help. I will get back to it in the morning, hopefully add some knowledge from a good answer and review what I’ve learned so far.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Telephone Number Validator
Link to the challenge: