表单验证的插件
引入:
<script src="http://localhost:1159/Scripts/jquery-1.8.2.js"></script>
<script src="http://localhost:1159/Scripts/jquery.validate.js"></script>
使用:(具体提示去百度)
$(document).ready(function () {
$("#form_yz").validate({----------------绑定的ID
rules: {
userName: {
required: true,---------------表示必填
minlength: 5------------------最小长度(除了长度还有其他,去百度)
},
userPasword:{
required:true,
minlength: 5
},
userEaml: {
required: true,
email: true
}
},
messages: {
userName: {
required: "*",-----------------------必填而未填时候提示
minlength: "短了"---------------------长度不符合时提示(和上面rules中各项一一对应)
},
userPasword: {
required: "*",
minlength: "短了"
},
userEaml: {
required: "*",
email: "不对"
}
}
})
})
HTML使用:
<form id="form_yz" action="" method="post">
<table>
<tr>
用户名
<td><input type="text" name="userName" /></td>
</tr>
<tr>
密码
<td><input type="text" name="userPasword" /></td>
</tr>
<tr>
邮箱
<td><input type="text" name="userEaml" /></td>
</tr>
<tr>
<td><input type="submit" /></td>
</tr>
</table>
</form>