Form Validation
Validate user-submitted form data before processing it. Try setting age below 18 or password shorter than 8 characters.
import { z } from 'zod';
const SignupSchema = z.object({
email: z.email(),
password: z.string().min(8),
age: z.number().int().min(18),
});
// Usage in a form handler:
// const result = SignupSchema.safeParse(formData);
// if (!result.success) return errors(result.error);type Signup = {
email: string;
password: string;
age: number;
}{
"email": "alice@example.com",
"password": "hunter42",
"age": 25
}