'SyntaxError: Invalid regular expression:
I'm pretty sure my regex is correct, but anytime I try to test the code, I get an invalid regular expression error with a nothing to repeat at the end.
I'll attach the code below
function checkPhoneNumber(phoneNumber) {
let phoneNumberValidation = RegExp("(\+1[ ]?)((\(?[0-9]{3}\)?[-\. ]?))([0-9]{3}[-\. ]?)([0-9]{4})");
if (phoneNumberValidation.test(phoneNumber)) {
return true;
} else {
return false;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
