excludes
Creates an excludes validation action.
const Action = v.excludes<TInput, TRequirement, TMessage>(requirement, message);
Generics
TInputextends ContentInputTRequirementextends ContentRequirement<ContentInput>TMessageextends ErrorMessage<ExcludesIssue<TInput, TRequirement>> | undefined
Parameters
requirementTRequirementmessageTMessage
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
ActionExcludesAction<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
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/excludes/