Spec-Zone.ru › Valibot

maxEntries

Creates a max entries validation action.

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

Generics

  • TInput extends EntriesInput
  • TRequirement extends number
  • TMessage extends ErrorMessage<MaxEntriesIssue<TInput, TRequirement>> | undefined

Parameters

  • requirement TRequirement
  • message TMessage

Explanation

With maxEntries you can validate the number of entries of an object. If the input does not match the requirement, you can use message to customize the error message.

Returns

  • Action MaxEntriesAction<TInput, TRequirement, TMessage>

Examples

The following examples show how maxEntries can be used.

Maximum object entries

Schema to validate an object with a maximum of 5 entries.

const MaxEntriesSchema = v.pipe(
  v.record(v.string(), v.number()),
  v.maxEntries(5, 'Object must not exceed 5 entries.')
);

Related

The following APIs can be combined with maxEntries.

Schemas

looseObject, object, objectWithRest, record, strictObject, variant

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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