Spec-Zone.ru › Valibot

maxGraphemes

Creates a max graphemes validation action.

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

Generics

  • TInput extends string
  • TRequirement extends number
  • TMessage extends ErrorMessage<MaxGraphemesIssue<TInput, TRequirement>> | undefined

Parameters

  • requirement TRequirement
  • message TMessage

Explanation

With maxGraphemes you can validate the graphemes of a string. If the input does not match the requirement, you can use message to customize the error message.

If you are looking for an equivalent of JavaScript's .length for maximum length checks, use maxLength instead. If you want to count every Unicode code point as one character—for example, to enforce the password length rules in NIST SP 800-63B or to match LENGTH() in PostgreSQL and SQLite or CHAR_LENGTH() in MySQL—use maxCodePoints instead.

Hint: The number of characters per grapheme is not limited. You may want to consider combining maxGraphemes with maxLength, maxCodePoints, or maxBytes to set a stricter limit.

Returns

  • Action MaxGraphemesAction<TInput, TRequirement, TMessage>

Examples

The following examples show how maxGraphemes can be used.

Max graphemes schema

Schema to validate a string with a maximum of 8 graphemes.

const MaxGraphemesSchema = v.pipe(
  v.string(),
  v.maxGraphemes(8, 'The string must not exceed 8 graphemes.')
);

Related

The following APIs can be combined with maxGraphemes.

Schemas

any, custom, string

Methods

pipe

Actions

maxCodePoints, maxLength

Utils

isOfKind, isOfType

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

Spec-Zone.ru

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