Skip to main content

digitsBetween

Validate that an integer's digit count falls within a closed range [min, max] (inclusive).

Signature

NguardValidators.Number.digitsBetween(minVal: number, maxVal: number): ValidatorFn
ParameterTypeDescription
minValnumberInclusive minimum digit count
maxValnumberInclusive maximum digit count

Reactive forms

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

const code = new FormControl('', [NguardValidators.Number.digitsBetween(4, 6)]);

Template-driven forms

<input ngModel name="code" [nguardDigitsBetween]="[4, 6]" />

The directive accepts a [number, number] tuple.

Error key

{ digitsBetween: true }

Notes

  • The value must be an integer. Floats fail.
  • The range is inclusive on both ends.
  • Sign is excluded from the count.
  • Throws RangeValidatorErrors.MinGreaterThanMax if minVal > maxVal.

See also