我在搞清楚这一点时遇到了一些困难。我有几个电话验证条件。如果符合条件,我想将用户带到另一个页面...我怎样才能最好地使用JavaScript?
请参阅随附的代码。
function validatePhone(){
var phone = document.getElementById("phone1").value;
if(phone.length === 0) {
console.log("phone number is required.");
producePrompt("Phone number is required.", "messagePrompt", "red");
return false;
}
if(!phone.match(/^\(?([0-9]{3})\)?[-.]?([0-9]{3})[-.]?([0-9]{4})$/))
{
producePrompt("Please enter a valid Phone number.", "messagePrompt", "red");
return false;
}
producePrompt("valid Number", "messagePrompt", "green");
return true;
}
function producePrompt(message, promptLocation, color) {
document.getElementById(promptLocation).innerHTML = message;
document.getElementById(promptLocation).style.color = color;
}
function remove_msg(){
producePrompt(" ", "messagePrompt", "red");
}

<form>
<p>Please enter your phone number below:</p>
<input type="tel" name="phone1" id="phone1" placeholder="(000)000-0000" onchange="validatePhone()"/ onmouseover="remove_msg()">
<label for="" id="messagePrompt"></label>
<br>
<input id="button" type="button" value="send message" onclick="validatePhone()"/>
</form>
&#13;