views:

27

answers:

1

I am trying to validate a field called promoRent, if only there is a number entered. It's not a required field but if entered it has to be greater than the lotRent. I have:

 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(); 

I am doing something silly as the validation does not run even if i enter a lesser amount than the lotrent. any ideas? thanks in advance.

A: 

this works great.

  ,promoRent : { PRgreaterThanLotRent : true }

then modified the PRgreaterThanLotRent function as follows:

 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;
        }
    });

sweeeeeeet...

FALCONSEYE