maxGraphemes
Creates a max graphemes validation action.
const Action = v.maxGraphemes<TInput, TRequirement, TMessage>(
requirement,
message
);
Generics
TInputextends stringTRequirementextends numberTMessageextends ErrorMessage<MaxGraphemesIssue<TInput, TRequirement>> | undefined
Parameters
requirementTRequirementmessageTMessage
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
.lengthfor maximum length checks, usemaxLengthinstead. 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 matchLENGTH()in PostgreSQL and SQLite orCHAR_LENGTH()in MySQL—usemaxCodePointsinstead.Hint: The number of characters per grapheme is not limited. You may want to consider combining
maxGraphemeswithmaxLength,maxCodePoints, ormaxBytesto set a stricter limit.
Returns
ActionMaxGraphemesAction<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
Methods
Actions
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/maxGraphemes/