How to validate a form with yup and formik?

I have a form with schema like this.

validationSchema: Yup.object({
      date: Yup.string()
        .required("Required!"),
      time: Yup.string()
        .required("Required!")
})

I need to validate whether this form is used to set a new date or update an existing date.

If the form is used to update an existing date, I want to notify the user if they can’t change the time 30 minutes before or 30 minutes after from the preset time.

For example, if preset time is 8AM.
User can’t change time to 7:30 or 8:30

46 thoughts on “How to validate a form with yup and formik?”

Leave a Comment