Skip to content

maxDate ​

The date is not later than the given one.

Signature ​

ts
function maxDate(date: Date | string | number | (() => Date), msg?: Message): Action<Date>

Parameters ​

ParameterTypeDescription
dateDate | string | number | (() => Date)A date or a function returning it — the function is called on every validation
msgMessageCustom error message

Error codes ​

CodeWhenDefault message
maxDateThe date is laterMust be on or before {date}

You can change the texts: see Messages & i18n.

Notes ​

Works with date and coerce.date. In the message {date} is the date as YYYY-MM-DD.

Example ​

Date of birth ​

ts
const birthday = pipe(coerce.date(), minDate('1900-01-01'), maxDate(() => new Date()));

See also ​