【发布时间】:2010-02-03 01:04:12
【问题描述】:
我正在尝试验证一个名为 promoRent 的字段,只要输入了一个数字。这不是必填字段,但如果输入,它必须大于 lotRent。我有:
jQuery.validator.addMethod("PRgreaterThanLotRent", function(value, element) {
return parseFloat($("#lotRent").val().replace(/[^\d\.]/g, '').replace(['.00'],'')) < parseFloat($("#promoRent").val().replace(/[^\d\.]/g, '').replace(['.00'],''));
});
$("#pricingForm").validate({
rules: { salesPrice: "required",
Rent: { required: true, greaterThanLotRent : true },
promoRent : { required: function() { if ($("#promoRent").val() != '') { PRgreaterThanLotRent : true }; } }
},
messages: { salesPrice: "<br/><span style='color:red'>Required!</span>",
mhRent: { required: "<br/><span style='color:red'>Required!</span>",
MHgreaterThanLotRent : "<br/><span style='color:red; '>Must be greater<br> than Lot Rent</span>" } ,
promoRent : { required: "",
PRgreaterThanLotRent : "<br/><span style='color:red; '>Must be greater<br> than Lot Rent</span>" }
}
}).form();
我正在做一些愚蠢的事情,因为即使我输入的金额少于 lotrent,验证也不会运行。有任何想法吗?提前致谢。
【问题讨论】:
标签: jquery validation