Im using the jQuery validate plugin and was wondering if there was a way to validate if the date entered into a field was a date like yyyy-mm-dd AND the the date falls betwe
Made a couple small corrections in Connor's code.
The resulting working code is:
$.validator.addMethod('daterange', function(value, element, arg) {
if (this.optional(element) && !value) {
return true;
}
var startDate = Date.parse(arg[0]),
endDate = Date.parse(arg[1]),
enteredDate = Date.parse(value);
if (isNaN(enteredDate)) {
return false;
}
return ( (isNaN(startDate) || (startDate <= enteredDate)) &&
(isNaN(endDate) || (enteredDate <= endDate)));
}, $.validator.format("Please specify a date between {0} and {1}."));
Then use it like this:
$("#some_date_input").rules("add",{daterange:['01/31/2001','01/31/2020']});