0

I have a form with two date fields, start_date and end_date. I want to create a rule that end_date must be greater then start_date, and if this condition returns false then to show validation errors as in the picture below.

enter image description here

So far I've tried to do so by creating a custom rule:

$.validator.addMethod("check_date", function(value, element) {
    var start_date = $("input[name='start_date']").val();
    var end_date = $("input[name='end_date']").val();
    return end_date(value) > start_date(value);
}, 'End date must be greater then start date.');

I'm not sure how exactly I set the rule and the message.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
RoyBar
  • 149
  • 2
  • 4
  • 14

1 Answers1

1

Got it.

   $.validator.addMethod("check_date", function(value, element) {
    var start_date = $("input[name='start_date']").val();
    var end_date = $("input[name='end_date']").val();
    return end_date > start_date;
}, 'End date must be greater then Start date.');
Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
RoyBar
  • 149
  • 2
  • 4
  • 14