Yup is a schema validation library for JavaScript that lets you describe the shape of your data once, then validate it anywhere — in a form, in an API request, or in a test. Instead of writing nested if statements to check that an email looks like an email and a password is long enough, you write a schema that reads almost like English.
What makes Yup different is its builder API. You chain methods to describe each field: what type it is, whether it is required, and what counts as valid. The schema then produces clear, field-specific error messages, and it can also cast and transform values before they reach your code.
npm install yup A signup form schema shows how readable it is:
import * as yup from 'yup' const signupSchema = yup.object({ name: yup.string().required('Name is required'), email: yup.string().email('Enter a valid email').required('Email is required'), password: yup.string().min(8, 'At least 8 characters').required('Password is required'), age: yup.number().min(18, 'You must be 18 or older').optional(), }) const result = await signupSchema.validate( { name: 'Arhan', email: 'not-an-email', password: 'short' }, { abortEarly: false }, ).catch((err) => err.errors) // ['Enter a valid email', 'At least 8 characters'] Yup is a great fit for forms, API validation, and anywhere untrusted input enters your app. It pairs naturally with Formik and React Hook Form, and the same schema can validate on the client and on the server.
The limits are honest ones. Yup adds a dependency where a few manual checks might do, and its error messages need customizing for a polished product. Very complex conditional rules can get verbose. But for form validation, that trade is usually worth it.
Next time you build a form, try Yup for one schema first: define it, validate a bad input, and read the errors. You will know within an hour whether it earns a permanent place in your toolkit.