notLength
Creates a not length validation action.
const Action = v.notLength<TInput, TRequirement, TMessage>(
requirement,
message
);
Generics
TInputextends LengthInputTRequirementextends numberTMessageextends ErrorMessage<NotLengthIssue<TInput, TRequirement>> | undefined
Parameters
requirementTRequirementmessageTMessage
Explanation
With notLength you can validate the length of a string or array. If the input does not match the requirement, you can use message to customize the error message.
Returns
ActionNotLengthAction<TInput, TRequirement, TMessage>
Examples
The following examples show how notLength can be used.
String schema
Schema to validate the length of a string.
const StringSchema = v.pipe(
v.string(),
v.notLength(8, 'The string must not be 8 characters long.')
);
Array schema
Schema to validate the length of an array.
const ArraySchema = v.pipe(
v.array(number()),
v.notLength(10, 'The array must not contain 10 numbers.')
);
Related
The following APIs can be combined with notLength.
Schemas
any, array, custom, instance, string, tuple, unknown
Methods
Actions
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/notLength/