Yup Schema Commonly Used Examples
CP
Posted on October 15, 2020
Here are two commonly used schema validations using Yup:
- Phone number validation with Regex
- How to compare two fields in Yup
import * as yup from "yup";
const phoneRegex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
const schema = yup.object().shape({
phone: yup.string().matches(phoneRegex, "Invalid phone."),
password: yup.string().required("Password is required"),
confirmPassword: yup
.string()
.oneOf([yup.ref("password")], "Mismatched passwords")
.required("Please confirm your password")
});
export default schema;
💖 💪 🙅 🚩
CP
Posted on October 15, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.