Validator

oneOf

Value must strict-equal one of the whitelisted options. Empty values pass.

Live demo

Try xs, sm, md, lg, or xl — anything else fails.

errors: null

Usage

import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const size = new FormControl('', [
  WrValidators.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
]);

Why ngwr provides this

Whitelist checks via Validators.pattern mean escaping every alternative into a regex. This takes the allowed values as plain data.

API

NameDescriptionTypeDefault
signatureFactory — call with the whitelist.<T>(allowed: readonly T[]) => ValidatorFn
comparisonStrict ===. Pass a typed const tuple to keep the union narrow on the consumer side.
error keyOn failure: { oneOf: { allowed: [...] } }. Empty value passes.{ oneOf: { allowed } }

See also