nanoid
Creates a Nano ID validation action.
const Action = v.nanoid<TInput, TMessage>(message);
Generics
TInputextends stringTMessageextends ErrorMessage<NanoIdIssue<TInput>> | undefined
Parameters
messageTMessage
Explanation
With nanoid you can validate the formatting of a string. If the input is not an Nano ID, you can use message to customize the error message.
Returns
ActionNanoIdAction<TInput, TMessage>
Examples
The following examples show how nanoid can be used.
Since Nano IDs are not limited to a fixed length, it is recommended to combine
nanoidwithlengthto ensure the correct length.
Nano ID schema
Schema to validate a Nano ID.
const NanoIdSchema = v.pipe(
v.string(),
v.nanoid('The Nano ID is badly formatted.'),
v.length(21, 'The Nano ID must be 21 characters long.')
);
Related
The following APIs can be combined with nanoid.
Schemas
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/nanoid/