Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joi - validate strings in mysql datetime format

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()
like image 850
Salar Avatar asked Nov 13 '18 09:11

Salar


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');

like image 118
Ali Momen Sani Avatar answered Sep 20 '22 23:09

Ali Momen Sani