Skip to main content
Version: 0.8.0

sizeBetween

Validate that the array item count is within [min, max] inclusive. A non-array value fails.

Signature

NguardValidators.Array.sizeBetween(min: number, max: number): ValidatorFn
ParameterTypeDescription
minnumberThe minimum number of items (inclusive)
maxnumberThe maximum number of items (inclusive)

Reactive forms

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

new FormControl([], [NguardValidators.Array.sizeBetween(1, 3)]);

Template-driven forms

<!-- The directive takes a [min, max] tuple -->
<input ngModel name="tags" [nguardSizeBetween]="[1, 3]" />

Error key

{ sizeBetween: true }

Notes

  • A non-array value (including null/undefined) fails.

See also