Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express Validator to validate DateTime

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'),
like image 318
okky Avatar asked May 06 '26 19:05

okky


1 Answers

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

like image 97
ssomename Avatar answered May 09 '26 07:05

ssomename



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!