Jquery验证不允许在输入字段中为零



如何禁止用户在输入字段中输入零?我使用的是Jquery验证插件和数字验证方法。我希望用户能够输入正数和负数,并且不允许零。

我试过使用greaterThan和lessThan方法,但似乎无法使它们正常工作。

$("#CPO_AddItemForm").validate({
errorElement: "em",
errorPlacement: function(error, element) {
error.appendTo(element.parent("div").next("div"));
},
rules: {
Stockno: {required: true, nowhitespace: true},
Descrip: "required",
Item_Qty: {required: true, number: true, greaterThan: 0},
Price: {required: true, number: true},
Unit: "required",
Vac_Occ: "required",
},
messages: {
Stockno: {required: "Required"},
Descrip: {required: "Required"},
Item_Qty: {required: "Required"},
Price: {required: "Required"},
Unit: {required: "Required"},
Vac_Occ: {required: "Required"},
},
});
$.validator.addMethod("notOnlyZero", function (value, element, param) {
return this.optional(element) || parseInt(value) > 0;
});
$('form').validate({
rules: {
yourFieldName: {
notOnlyZero: '0'
}
},
messages: {
yourFieldName: {
notOnlyZero: 'Message to show'
}
}
});

相关内容

  • 没有找到相关文章

最新更新