So I am trying to write code that will evaluate if a phone number is valid in one of three ways.
The first is the form xxx-xxx-xxxx, the second is (xxx) xxx-xxxx, and the third is xxxxxxxxxx.
Here’s my regular expression:
if (/^\d{3}-\d{3}-\d{4}$/.test(phoneVal) || /^\d{10}$/.test(phoneVal) || /^\(\d{3}\) \d{3}-\d{4}$/.test(phoneVal)) {
return true;
}
However whenever I put in what I would consider to be a valid phone number, it trips up this regular expression, and gives the error:
else {
alert("Please put in a correct phone number");
return false;
}
You’re getting the element rather than its value. Use the
valueproperty: