Enumerator modifier
A modifier which creates a validation rule to ensure that a given value is one of the allowed values in the provided list.
Schemas
number
: Learn morestring
: Learn moredate
: Learn more
Arguments
input
- The array of values or TypeScript enum which the input value must be one ofmessage?
- A custom object with error messages to be displayed when validation fails or there are type errors
Example
import { enumerator, number } from '@nordic-ui/validathor';
const schema = number([enumerator([0, 25, 50, 75, 100])]);
try {
const parsedValue = schema.parse(75);
console.log('Parsed value:', parsedValue);
} catch (error) {
console.error('Parsing failed:', error.message);
}