I want to validate DateTime like this code below
{
"data": {
"start": "2018-05-12 08:00:00"
}
}
How to combine isISO8601() and match(regex) to validate date & time in start
body('*.start')
.exists()
.not()
.isEmpty()
.withMessage('start cannot be empty')
.isISO8601('yyyy-mm-dd')
.matches('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$')
.withMessage('start must be in correct format yyyy:mm:dd hh:mm:ss'),
The express-validator documentation does it like so now:
check('date-of-birth').isISO8601().toDate(),
source:
Validation Chain API v6 Example
Validation Chain API v7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With