<script>
$(document).ready(function(){
var form = $("#contact_form");
var FName = $("#fname"); //Creates Variables from forms
var FNameInfo = $("#fnameInfo");
var LName = $("#lname");
var Tele = $("#tele");
var Email = $("#email");
FName.blur(validateFName);
form.submit (function(){
if (validateFName & validateSName & validateTele() & validateEmail() ){ //If it passes all of these then return true
return true;
}else {
return false;
}
});
function validateFName () {
if (FName.val().length < 5 || FName.val == "0"){
FName.addClass("error");
FNameInfo.text("Incorrect Name");
FNameInfo.addClass("error");
return false;
}
else {
FName.removeClass("error");
FNameInfo.text("Whats your fname" );
FNameInfo.removeClass("error");
return true;
}
}
});
</script>
<form action="" method="get" id = "contact_form">
<div>
<label for ="name">First Name </label>
<input id = "fname" name = "fname" type = "text"/>
<span id = "fnameInfo" > Whats your first name?</span>
</div>
<div>
<label for ="lname">Last Name </label>
<input id = "lname" name = "lname" type = "text"/>
<span id = "lnameInfo" > Whats your last name?</span>
</div>
<div>
<label for ="tele">Telephone </label>
<input id = "tele" name = "tele" type = "text"/>
<span id = "fnameInfo" > Telephone</span>
</div>
<div>
<label for ="email">email </label>
<input id = "email" name = "email" type = "text"/>
<span id = "fnameInfo" > Whats your last email?</span>
</div>
<div>
<input id = "send" name = "send" type = "submit" value = "send"/>
</div>
</form>
好的,对于名字我希望用户在输入数字而不是字母时显示错误。我需要打开表单以确定错误,因此不会应用任何限制,只有在用户输入数字时出现错误