• Overview
@angular/forms/signals

maxDate

function
stablesince v22.0

Binds a validator to the given path that requires the value to be less than or equal to the given maxDate. This function can only be called on date paths. In addition to binding a validator, this function adds MAX property to the field.

API

function maxDate<
  TValue extends Date | null,
  TPathKind extends PathKind = PathKind.Root,
>(
  path: SchemaPath<TValue, 1, TPathKind>,
  maxDateValue: Date | LogicFn<TValue, Date | undefined, TPathKind>,
  config?: BaseValidatorConfig<TValue, TPathKind> | undefined,
): void;
@parampathSchemaPath<TValue, 1, TPathKind>

Path of the field to validate

@parammaxDateValueDate | LogicFn<TValue, Date | undefined, TPathKind>

The maximum date, or a LogicFn that returns the maximum date.

@paramconfigBaseValidatorConfig<TValue, TPathKind> | undefined

Optional, allows providing any of the following options:

  • error: Custom validation error(s) to be used instead of the default maxDateError() or a function that receives the FieldContext and returns custom validation error(s).
@returnsvoid

Description

Binds a validator to the given path that requires the value to be less than or equal to the given maxDate. This function can only be called on date paths. In addition to binding a validator, this function adds MAX property to the field.

When the field is bound to an <input type="date">, its value is a Date at midnight UTC, so the maximum should be built the same way, e.g. new Date('2026-08-31') or new Date(Date.UTC(2026, 7, 31)). A Date created from local time, such as new Date(2026, 7, 31) or new Date(), is offset by the user's time zone, which can make the limit date itself invalid.

Jump to details