Im trying to validate a datepicker form to check if the first selected date is before the second selected date as shown here: https://www.dropbox.com/s/uwmx64vogm5viyp/Screenshot%202014-04-03%2014.20.38.png
The way I'm currently doing it is:
buildComparisonRule({
name: "dateBefore",
message: "You must select an end date that is after the start date",
validator: function(value, comparedTo){
var FirstDate = new Date(value);
var SecondDate = new Date(comparedTo);
return FirstDate.getTime() < SecondDate.getTime();
}
});
var form = document.getElementById("datepicker_form");
validator(form, [{
name: "start_date",
rules: "dateBefore[end_date]"
}]).onError(function(errors){
console.log(Object.keys(errors))
for (var error in errors){
//alert(errors[error])
}
$('#start_date').parent().addClass('error');
});
Using the valkyr.js validation libary.
The problem is that atm it only validates on the first part of the DD/MM/YYYY rather than entire string.
Is there any ways to validate on the whole date rather than just the one part of it?