我的验证函数有问题,我只在一个函数中完成了它,我想添加电子邮件验证,例如@和数字 1-9。我该如何添加它?
html:
<form onsubmit="return validate();" name="formValidation">
<label>First Name:</label>
<input type="text" name="firstName" /><br /><br />
<label>Last Name:</label>
<input type="text" name="lastName" /><br /><br />
<label>E_mail:</label>
<input type="text" name="Email" /><br /><br />
<label>Confirm E_mail:</label>
<input type="text" name="confirmEmail" /><br /><br />
<label>Address:</label>
<input type="text" name="Address" /><br /><br />
<label>Telephone nr:</label>
<input type="text" name="telephoneNr" /><br /><br />
<br />
<p>submit your form: </p><input type="submit" value="Submit" />
</form>
js:
function validate(){
if(document.formValidation.firstName.value == "" ||
document.formValidation.lastName.value == "" ||
document.formValidation.Email.value == "" ||
document.formValidation.confirmEmail.value == "" ||
document.formValidation.Address.value == "" ||
document.formValidation.telephoneNr.value == "")
{
alert("Please fill all the boxes before submitting!");
return false;
} else {
alert('Your form has been submitted!');
}
}