includes
Creates an includes validation action.
const Action = v.includes<TInput, TRequirement, TMessage>(requirement, message);
Generics
TInputextends ContentInputTRequirementextends ContentRequirement<ContentInput>TMessageextends ErrorMessage<IncludesIssue<TInput, TRequirement>> | undefined
Parameters
requirementTRequirementmessageTMessage
Explanation
With includes 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
ActionIncludesAction<TInput, TRequirement, TMessage>
Examples
The following examples show how includes can be used.
String schema
Schema to validate that a string contains a specific substring.
const StringSchema = v.pipe(
v.string(),
v.includes('foo', 'The string must contain "foo".')
);
Array schema
Schema to validate that an array contains a specific string.
const ArraySchema = v.pipe(
v.array(v.string()),
v.includes('foo', 'The array must contain "foo".')
);
Related
The following APIs can be combined with includes.
Schemas
any, array, custom, instance, string, tuple, unknown
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/includes/