Validator.js: Bug in Date validation, isDate() function

Created on 28 Jul 2020  路  2Comments  路  Source: validatorjs/validator.js

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]

馃嵖 discussion 馃悰 bug

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mren picture mren  路  3Comments

karladler picture karladler  路  3Comments

woverton picture woverton  路  4Comments

spyshower picture spyshower  路  3Comments

jaxkodex picture jaxkodex  路  3Comments