Back to Agent Skills
Security & Quality
Yup Schema Validation
Build expressive validation schemas with Yup for form validation and data parsing in JavaScript applications.
Claude Code Cursor Copilot Windsurf
Overview
Yup is a schema validation library that provides a fluent, chainable API for defining validation rules. It has been the go-to validation library for React applications, particularly with Formik form library integration. Yup schemas define both the shape and validation constraints of data, with built-in type coercion that converts strings to numbers, dates, and booleans automatically.
The library supports conditional validation through the `.when()` method, allowing validation rules to depend on other field values. This is particularly useful for complex forms where field requirements change based on user selections. Yup also provides `.test()` for custom async validation, enabling checks against APIs like uniqueness validation.
Yup's error messages are customizable at both the schema level and globally. The library supports localization through custom locale objects, making it easy to provide error messages in multiple languages. While similar to Zod in purpose, Yup focuses on runtime validation with automatic coercion, making it particularly well-suited for form validation where input values start as strings.
The library supports conditional validation through the `.when()` method, allowing validation rules to depend on other field values. This is particularly useful for complex forms where field requirements change based on user selections. Yup also provides `.test()` for custom async validation, enabling checks against APIs like uniqueness validation.
Yup's error messages are customizable at both the schema level and globally. The library supports localization through custom locale objects, making it easy to provide error messages in multiple languages. While similar to Zod in purpose, Yup focuses on runtime validation with automatic coercion, making it particularly well-suited for form validation where input values start as strings.
Who Is This For?
- Validate form inputs with Formik and Yup schemas
- Define conditional validation rules for complex forms
- Validate API request data with custom error messages
- Set up multilingual validation error messages
Installation
Setup for Claude Code
npm install yup Configuration
import * as yup from "yup"
const schema = yup.object({
name: yup.string().required("Name is required").min(2),
email: yup.string().email("Invalid email").required(),
age: yup.number().positive().integer().nullable(),
website: yup.string().url().optional(),
password: yup.string().min(8).required(),
confirmPassword: yup.string()
.oneOf([yup.ref("password")], "Passwords must match")
.required(),
})
await schema.validate(formData, { abortEarly: false }) Explore AI Tools
Discover the best AI tools that complement your skills
Read AI & Design Articles
Tips and trends in the world of design and AI
Related Skills
Security & Quality
Snyk Security Scan
Detect vulnerabilities in your dependencies and application code. Get actionable remediation advice and automatic fix pull requests.
Claude Code Codex Copilot
Security & Quality SonarQube Code Quality
Run continuous code quality and security analysis to catch bugs, code smells, and vulnerabilities before they reach production.
Claude Code Codex Copilot
Security & Quality OWASP ZAP Security Testing
Perform automated web application security testing to find common vulnerabilities like XSS, injection flaws, and misconfigurations.
Claude Code Codex