jQuery:validate添加自定义验证
jQuery.validator.addMethod添加自定义的验证规则
addMethod:name, method, message
简单实例:单个验证的添加
<script type="text/javascript">
$("#tinyphp").validate({
// 添加验证规则
rules: {
isZipCode: { //验证邮箱
isZipCode: true
}
}
});
</script>
<script type="text/javascript" src="jquery.validate.js"></script>
$("#tinyphp").validate({
// 添加验证规则
rules: {
isZipCode: { //验证邮箱
isZipCode: true
},
userName:{
required: true,
userName: true,
rangelength: [5,10]
}
},
//重设提示信息,可省略
messages:{
userName: {
required: "请填写用户名",
rangelength: "用户名必须在5-10个字符之间"
}
}
});