我正在try 在react.js上使用formik和yup进行验证.在我为YUP创建的模式中,有一个邮箱和密码部分,我只想要show all the errors in the password section at the same time, the errors in the email section should be displayed in order,但我做不到,但如果你能帮助我,我将非常感激.
下面是我如何创建YUP对象的
const validationPageTwo = Yup.object({
email: Yup.string().required("Required field"),
password: Yup.string()
.required("Required field password")
.matches(/^(?=.{8,})/, "Must Contain 8 Characters")
.matches(/^(?=.*[!@#\$%\^&\*])/, " One Special Case Character")
.matches(/^(?=.*[0-9])/, " One Number")
.matches(/^(?=.*[a-z])/, " One Lowercase")
.matches(/^(?=.*[A-Z])/, " One Uppercase"),
});
const formik = useFormik({
initialValues: {
name: "",
surname: "",
email: "",
password: "",
},
validationSchema: page === 1 ? validationPageOne :
validationPageTwo,
onSubmit: (values) => {
if (page === 1) {
setPage(2);
} else {
alert(JSON.stringify(values));
}
},
});