Incorrect date formats like YYYY-MM/DD and YYYY/MM-DD which contains both hyphen - and forward slash / are being wrongly validated as true.
validator.isDate("2020-10/12"); // returns true
validator.isDate("2020/10-12"); // returns true
Expected Behavior
I think in such cases, isDate() function should return false
Additional context
Validator.js version:^13.1.1
Node.js version:v12.16.1
OS platform: [windows]
I am not totally sure these are incorrect.... I mean, they can be parsed, and to a human eye these are readable dates...
If this is only supposed to accept ISO8601 dates, then slashes are not allowed at all. But if both are allowed, it makes sense to allow a mix of the two...
In my opinion, I will go with the version that has a strict mode and one without.
For instance, if we pass
const date = "2020/10-12"
// strictMode is false in default
validator.isDate(date, stictMode: true) // false
validator.isDate(date) // return true
validator.isDate(date, strictMode: false) // return true
Also, if you take keen consideration with isDate(), there is an option to pass format.
I am still open for more discussion on the same.
Most helpful comment
In my opinion, I will go with the version that has a
strict modeand one without.For instance, if we pass
Also, if you take keen consideration with
isDate(), there is an option to passformat.I am still open for more discussion on the same.