【问题标题】:another jquery validation question另一个jQuery验证问题
【发布时间】: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


    【解决方案1】:

    这很好用。

      ,promoRent : { PRgreaterThanLotRent : true }
    

    然后修改PRgreaterThanLotRent函数如下:

     jQuery.validator.addMethod("PRgreaterThanLotRent", function(value, element) {
            if ($("#promoRent").val() != '') {                                                  
            return parseFloat($("#lotRent").val().replace(/[^\d\.]/g, '').replace(['.00'],'')) <  parseFloat($("#promoRent").val().replace(/[^\d\.]/g, '').replace(['.00'],''));
            } else {
            return true;
            }
        });
    

    亲爱的……

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      相关资源
      最近更新 更多