Spec-Zone.ru › Valibot

values

Creates a values validation action.

const Action = v.values<TInput, TRequirement, TMessage>(requirement, message);

Generics

  • TInput extends ValueInput
  • TRequirement extends readonly TInput[]
  • TMessage extends ErrorMessage<ValuesIssue<TInput, TRequirement>> | undefined

Parameters

  • requirement TRequirement
  • message TMessage

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 picklist schema instead if you want the type to match the union of specific values.

Returns

  • Action ValuesAction<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

pipe

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/values/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API