0
我想驗證一個名爲promoRent的字段,如果只有輸入的數字。這不是必填字段,但是如果輸入它必須大於lotRent。我有:另一個jquery驗證問題
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不運行。有任何想法嗎?提前致謝。