maxDate
The date is not later than the given one.
Signature
ts
function maxDate(date: Date | string | number | (() => Date), msg?: Message): Action<Date>Parameters
| Parameter | Type | Description |
|---|---|---|
date | Date | string | number | (() => Date) | A date or a function returning it — the function is called on every validation |
msg | Message | Custom error message |
Error codes
| Code | When | Default message |
|---|---|---|
maxDate | The date is later | Must 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()));