Spec-Zone.ru › Valibot

excludes

Creates an excludes validation action.

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

Generics

  • TInput extends ContentInput
  • TRequirement extends ContentRequirement<ContentInput>
  • TMessage extends ErrorMessage<ExcludesIssue<TInput, TRequirement>> | undefined

Parameters

  • requirement TRequirement
  • message TMessage

Explanation

With excludes you can validate the content of a string or array. If the input does not match the requirement, you can use message to customize the error message.

Returns

  • Action ExcludesAction<TInput, TRequirement, TMessage>

Examples

The following examples show how excludes can be used.

String schema

Schema to validate that a string does not contain a specific substring.

const StringSchema = v.pipe(
  v.string(),
  v.excludes('foo', 'The string must not contain "foo".')
);

Array schema

Schema to validate that an array does not contain a specific string.

const ArraySchema = v.pipe(
  v.array(v.string()),
  v.excludes('foo', 'The array must not contain "foo".')
);

Related

The following APIs can be combined with excludes.

Schemas

any, array, custom, instance, string, tuple, unknown

Methods

pipe

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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