validator.js
validator.js copied to clipboard
validator.isDate seems to return true for just about anything
> var x = 99999;
> validator.isDate(x);
true
> var x = "99999";
> validator.isDate(x);
true
> var x = 0.99999
> validator.isDate(x);
false
> var x = 0.1
> validator.isDate(x);
true
> var x = "foo";
> validator.isDate(x);
false
I believe it requires validator.toDate for string sanitization? e.g.
str = validator.toDate(str); validator.isDate(str);
It doesn't require sanitization with toDate first. The isDate validator uses the built-in Date.parse() function which is quite lenient with what it accepts.
You can see what it's doing by calling new Date(Date.parse(str)), e.g.
> new Date(Date.parse('0-5-23'));
Tue May 23 2000 00:00:00 GMT+0900 (JST)
> new Date(Date.parse('0-5'));
Mon May 01 2000 00:00:00 GMT+0900 (JST)
> new Date(Date.parse('0'));
Sat Jan 01 2000 00:00:00 GMT+0900 (JST)
> new Date(Date.parse('0.1'));
Sat Jan 01 2000 00:00:00 GMT+0900 (JST)
If you need stricter date validation, I suggest using isISO8601 or regular expressions.