1 // 添加自定义校验规则,校验正整数
2 jQuery.validator.addMethod("positiveinteger", function(value, element) {
3 var Val = parseInt(value);
4 return Val > 0 && (Val + "") == value;
5 }, "请输入正整数");
6
7 // 表单验证
8 $('#rebate_num_form').validate({
9 errorPlacement: function(error, element) {
10 $(element).next('.field_notice').hide();
11 $(element).parent().append(error);
12 },
13 success: function(label) {
14 label.addClass('right').text('OK!');
15 },
16 onkeyup: false,
17 rules: {
18 num: {
19 required: true,
20 number: true,
21 positiveinteger: true
22 }
23 },
24 messages: {
25 num: {
26 required: '不能为空',
27 number: '只能是数字',
28 positiveinteger: '只能是正整数'
29 }
30 }
31 });