values
Creates a values validation action.
const Action = v.values<TInput, TRequirement, TMessage>(requirement, message);
Generics
TInputextends ValueInputTRequirementextends readonly TInput[]TMessageextends ErrorMessage<ValuesIssue<TInput, TRequirement>> | undefined
Parameters
requirementTRequirementmessageTMessage
Explanation
With values you can validate the value of a string, number, boolean or date. If the input does not match one of the values in the requirement, you can use message to customize the error message.
This action does not change the type of the pipeline. Use the
picklistschema instead if you want the type to match the union of specific values.
Returns
ActionValuesAction<TInput, TRequirement, TMessage>
Examples
The following examples show how values can be used.
Number schema
Schema to validate a number with specific values.
const NumberSchema = v.pipe(
v.number(),
v.values([5, 15, 20], 'The number must be one of the allowed numbers.')
);
Related
The following APIs can be combined with values.
Schemas
any, bigint, boolean, custom, date, number, string, unknown
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/values/