I want to validate if the input of a select element is in the array of valid values with Vue + Valibot.
I have a select with numeric values (IDs) and I need to check if is a valid ID.
So first I check if matches the numeric regex, and then I don't know how to add some validator for checking if the value is in the array.
import * as v from "valibot";
const validValues = ['1', '2', '4'];
const Schema = v.object({
// ...
user: v.string([v.regex(/^\d+$/)]),
});
Edit:
I just saw the custom validator, and it worked doing:
user: v.string([
v.regex(/^\d+$/),
v.custom((i) => validValues.includes(i), "not valid"),
]),
But there is some premade validator that achieves that?