Here's Maxim Gershkovich's solution spelled out a little more:
jQuery.validator.methods.date = function (value, element) {
if (value) {
try {
$.datepicker.parseDate('dd/mm/yy', value);
} catch (ex) {
return false;
}
}
return true;
};
Notes:
- This depends on the jQuery datepicker method that comes with jQuery UI
This is actually more robust that the native date validation that comes with jQueryValidate.
According to the docs on date validation:
Returns true if the value is a valid date. Uses JavaScript's built-in Date to test if the date is valid, and therefore does no sanity checks. Only the format must be valid, not the actual date, eg 30/30/2008 is a valid date.
Whereas parseDate will check that the date is valid and actually exists.