I try to validate my schema using yup:
import * as yup from "yup";
let schema = yup.object().shape({
name: yup.string().min(5)
});
const x = { name: "" };
// check validity
schema
.validate(x, { abortEarly: false })
.then((result) => {
console.log({ result });
})
.catch((err) => {
console.log({ err });
});
The name is empty in x object, But yup throw an error of min. Why? Which rule can be applied to solve this problem?
I need to validate for min only if I have any characters in x. How can I do so using yup functions?