Skip to main content
Version: 0.9.0

inList

The value must be one of the given numbers. The control value is coerced numerically (so '2' matches 2); non-numeric values fail.

Signature​

NguardValidators.Number.inList(...values: number[]): ValidatorFn
ParameterTypeDescription
...valuesnumber[]The allowed values

Reactive forms​

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

new FormControl('', [NguardValidators.Number.inList(1, 2, 3)]);

Template-driven forms​

<!-- Array form -->
<input ngModel name="size" [nguardNumberInList]="[1, 2, 3]" />

<!-- Single value shorthand -->
<input ngModel name="size" [nguardNumberInList]="1" />

Error key​

{ inList: true }

Notes​

  • Numeric coercion — '3' matches 3. Non-numeric values fail.

See also​