I need a validation of array of strings(tags). Strings should be in lower case, max 14 and not required.
I tried this, but I need it to make not required, i.e. they should be allowed to be null, undefined or an empty array
tags: yup.array()
.max(14, "Max 14 tags allowed!")
.test("is tag", "All words to lower case!", (arr) => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] !== arr[i].toLowerCase()) {
return false;
}
}
return true;
}),
You can add
nullableto allownullandundefined. I also included a much shorter checking if the tags are all lowercase.