Hi I am not able to pass 3 cases. How do I put a condition so that 3 digits must be surrounded by 2 parenthesis at the same time. For example I want to return true if “(555)” but false for"(555" and false for “555)”. So the area of code to look at is ^1?\s?\W?\d{3}\W?.. What do I do to put condition so that \W around \d{3} must be present at the same time. If this is not the way of looking at this problem please guide. Thank you
function telephoneCheck(str) {
let regex = /^1?\s?\W?\d{3}\W?\W?\d{3}\W?\d{4}$/gi;
return regex.test(str);
}
console.log(telephoneCheck("1 555)555-5555"));
console.log(telephoneCheck("555)-555-5555"));
console.log(telephoneCheck("(555-555-5555"));
Well, the parentheses are special characters on a regular expression, hence you need to escape them to be able to use them as part of the string to match.