我有一个表格
<form id="Register" method="post" onsubmit="return validateForm()">
<p><label>Your Email</label><input type="text" name="email"/></p>
<p style="margin-left:27%;"><input type="submit" name="submit" value="Submit" /></p>
</form>
我使用这个表单的 javascript 验证是
function validateForm() {
var x = document.forms["Register"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
return false;
}
}
我有两个或多个表格
<form id="Login" method="post" >
<p><label>Email</label><input type="text" name="Log_email" /></p>
<p style="margin-left:27%;"><input type="submit" name="submit" value="Login" /></p>
</form>
<form id="forgot" method="post">
<p><label>Your Email</label><input type="text" name="email"/></p>
<p style="margin-left:27%;"><input type="submit" name="submit" value="Submit" /></p>
</form>
我如何通常为所有这些表单重写 javascript 验证。