0

I am using jQuery validate plugin and i want to make sure that end date is greater than start date. Is it possible to check this using jQuery validate plugin. Can anyone please help me on this. Your help would be very much appreciated.

Thanks.

user113716
  • 318,772
  • 63
  • 451
  • 440
RShrestha
  • 1
  • 1
  • 2

1 Answers1

3

Check out this post for the end date greater than start date problem:

Validate that end date is greater than start date with jQuery

Taking it a step further, you can do just about anything you want with the validator plugin by writing a custom method. You don't have to use the generic input parameters either. You can reference any selector on the page. All the method cares about is whether or not it returns true or false.

jQuery.validator.addMethod( "acustomvalidator",
    function(value, element) {

        // check some inputs by a selector on the page, or do whatever...
        if( $('#yourinput1').val().length > 0 || $('#yourinput2').val().length > 0 )
            return true;
        else
            return false;
    },
    "Please fill out one of my input boxes."
);


<input type="txt" class="acustomvalidator" id="yourinput1" />
<input type="txt" class="acustomvalidator" id="yourinput2" />
Community
  • 1
  • 1