between
Validate that a numeric value falls within a closed range [min, max] (inclusive).
Signature
NguardValidators.Number.between(minVal: number, maxVal: number): ValidatorFn
| Parameter | Type | Description |
|---|---|---|
minVal | number | Inclusive lower bound |
maxVal | number | Inclusive upper bound |
Reactive forms
import { FormControl } from '@angular/forms';
import { NguardValidators } from 'ng-nguard';
const rating = new FormControl('', [NguardValidators.Number.between(1, 5)]);
Template-driven forms
<input ngModel name="rating" [nguardBetween]="[1, 5]" />
The directive accepts a [number, number] tuple.
Error key
{ between: true }
Notes
- The check is inclusive on both ends —
between(1, 5)accepts1and5. - Numeric strings work —
'3'passesbetween(1, 5). null,undefined, empty string,NaN,Infinityall fail.- Throws
RangeValidatorErrors.MinGreaterThanMaxifminVal > maxVal.
See also
min/max— single-bound variantsgreaterThanOrEqual/lesserThanOrEqual— same operators but compare against a sibling field instead of a literal