joi-date
Installation:

npm: npm install @hapi/joi-date

yarn: yarn add @hapi/joi-date

Compatibility

This version requires joi v16 or newer. For previous versions of joi use version 1.x of this module.

Usage

const Joi = require('@hapi/joi')
    .extend(require('@hapi/joi-date'));

const schema = Joi.date().format('YYYY-MM-DD').utc();

Rules

date.format(format)

Specifies the allowed date format:

  • format - string or array of strings that follow the moment.js format.
const schema = Joi.date().format(['YYYY/MM/DD', 'DD-MM-YYYY']);

date.utc()

Dates will be parsed as UTC instead of using the machine's local timezone.

const schema = Joi.date().utc().format(['YYYY/MM/DD', 'DD-MM-YYYY']);
clipboard