Spec-Zone.ru › Valibot

multipleOf

Creates a multiple of validation action.

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

Generics

  • TInput extends number | bigint
  • TRequirement extends number | bigint
  • TMessage extends ErrorMessage<MultipleOfIssue<TInput, TRequirement>> | undefined

Parameters

  • requirement TRequirement
  • message TMessage

Explanation

With multipleOf you can validate the value of a number. If the input does not match the requirement, you can use message to customize the error message.

Returns

  • Action MultipleOfAction<TInput, TRequirement, TMessage>

Examples

The following examples show how multipleOf can be used.

Even number schema

Schema to validate an even number.

const EvenNumberSchema = v.pipe(
  v.number(),
  v.multipleOf(2, 'The number must be even.')
);

Related

The following APIs can be combined with multipleOf.

Schemas

any, bigint, custom, number, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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