Joi - validate strings in mysql datetime format

Viewed 9348

I want to validate input strings which are in mysql datetime format like this:
YYYY-MM-DD HH:mm:ss
2018-10-12 19:32:55

How can I do that?
I have used this code but it allows strings like 222018-10-12 19:32:55 which are invalid.

created_at: Joi.date().required()
1 Answers

As of version v10 joi.format() was removed and instead you can use joi-date-extensions which provides validation helpers like this:

Joi.date().format('YYYY-MM-DD');

Related