我有一個驗證函數的問題,我只在一個函數中做了它,我想添加電子郵件的驗證,例如@和數字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!');
}
}
這篇文章可能能夠幫助http://stackoverflow.com/questions/46155/validate-email-address-in-javascript –