1.static-method-I18N.html
<html>
<head>
<meta charset="UTF-8" />
<script src="jquery-1.6.4.js" type="text/javascript"></script>
<script src="jquery.validate.min.js" type="text/javascript"></script>
<script src="messages_zh.js" type="text/javascript"></script>
<script language="javascript">
<!--
$(function(){
//自定义校验规则
$.validator.addMethod(
"zipCode",
function(value, element, params){
return /^[0-9]{6}$/.test(value);
},
"请输入正确的邮政编码");
$.validator.addMethod(
"greater",
function(value, element, params){
return parseInt(value) > parseInt($(params[0]).val());
},
//格式化输出错误信息
jQuery.validator.format("输入的值必须大于{1}的值"));
//改变validate方法的默认参数设置
$.validator.setDefaults({
onkeyup: false
});
//将一组校验规则绑定到一个class中
$.validator.addClassRules({
zip: {
required: true,
digits: true,
minlength: 6,
maxlength: 6
}
});
$("#validate").validate({
rules: {
zipCode: {
zipCode: true,
required: true
},
num1: {
required: true,
digits: true
},
num2: {
required: true,
digits: true,
greater: ["#num1", "NUMBER"]
}
}
});
});
-->
</script>
</head>
<body>
<form id="validate">
<p>
ZIPCODE(Required):
<input type="text" id="zipCode" name="zipCode" />
</p>
<p>
ZIPCODE2(Required):
<input type="text" id="zipCode2" name="zipCode2" class="zip"/>
</p>
<p>
NUMBER(Required):
<input type="text" id="num1" name="num1" />
</p>
<p>
GREATER-NUMBER(Required):
<input type="text" id="num2" name="num2" />
</p>
<input type="submit" value="提交"/>
</form>
</body>
</html>
2.参考资料
http://jqueryvalidation.org/documentation/