React Password and Confirm Password Validation using Yup

In this example i am going to discuss about password and confirm password validation in react native. To validate password and confirm password i am going to use formik and yup. So in this formik yup confirm password validation, you will learn it from step by step.

So if you don't know confirm password formik react native validation then this tutorial is for you. You can show this error message easily if there is wrong password. So let's see the example code of password and confirm password validation in react native using formik and yup.

Example code:

const validationSchema = Yup.object().shape({
    password: Yup.string().min(6).required("Password Required"),
    confirm_password: Yup.string()
      .min(6)
      .when("password", {
        is: (val: any) => (val && val.length > 0 ? true : false),
        then: Yup.string().oneOf(
          [Yup.ref("password")],
          "Both password need to be the same"
        ),
      })
      .required("Confirm Password Required"),
  });

 

Hope it can help you.

 

author-image
Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js