-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
date
validation use the following
return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString());
If value
is an invalid date (say) '30/30/2008' then in Chrome, it will return false
(new Date('30/30/2000');
returns Invalid date
), but in FireFox, it will return true
(new Date('30/30/2000');
returns '29th June 2010', a valid date, but not the same date as that being validated).
Not only is the result of validation inconsistent across browsers, but an invalid date is considered valid (I note this is currently the documented behavior)
Refer this fiddle for a possible alternative for validation of dates - by creating a new date from the numeric components of the value and comparing it with the value returned by new Date(value)
.
Note the fiddle also include a value for the date format which could be added as an option to the validator so that dates in different cultures could also be validated.