Skip to main content

max

Validate that a numeric value is less than or equal to a literal maximum.

Signature

NguardValidators.Number.max(maxVal: number): ValidatorFn
ParameterTypeDescription
maxValnumberInclusive maximum allowed value

Reactive forms

import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';

const quantity = new FormControl('', [NguardValidators.Number.max(100)]);

Template-driven forms

<input ngModel name="quantity" [nguardMax]="100" />

Error key

{ max: true }

Notes

  • The check is <= (inclusive). max(100) accepts 100.
  • Numeric strings work — '100' passes max(100).
  • null, undefined, empty string, NaN, Infinity all fail.

See also

  • min — lower-bound counterpart
  • between — both bounds in one validator
  • lesserThanOrEqual — same operator but compares against a sibling field instead of a literal