I am modifying an existing project, where I want to validate the start date(From) and end date(To) using jquery. The requirement is that End date(To) cannot be less than the Start date(from). Below is my html code and I add the jquery code I've written. But the date is not validated and it doesn't display any error message. Once I click the submit button it submit successfully without any error. I refer the following question to write the jquery part, but does not work. I really appreciate if some one can help me to resolve this. Thanks in advance.
Using jquery Validation 'greaterthan' function
var validator = $("#add_cetificate").validate();
$("#valid_to").rules('add', { greaterThan: "#valid_from" });
$.validator.addMethod('greaterThan', function(value, element, param){
var startDate = $(param).val();
var endDate = value ;
return endDate > startDate;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/additional-methods.min.js"></script>
<div class="form-group">
<label for="" class="col-sm-2 control-label">Valid From<span class="star"> * </span></label>
<div class="col-sm-3">
<input type="text" class="form-control datepicker" name="valid_from[]" id="valid_from" required="required">
</div>
<label for="" class="col-sm-2 control-label"> To <span class="star"> * </span></label>
<div class="col-sm-3">
<input type="text" class="form-control datepicker" name="valid_to[]" id="valid_to" required="required">
</div>
</div>