Forms, validation and schemas: live code examples
20 examples for 4 libraries. Open one to read how it works, run it in your browser and change it, by hand or with AI.
All 231 examples UI components and icons Utilities Animation and motion 3D and graphics Web frameworks State and data fetching Markdown, editors and content Files, images and media Styling and CSS Auth and security libraries Charts and data visualisation HTTP clients and networking Game development
Zod 5 examples · usage and stats
Handling errors with ZodError in ZodChange the invalid object so only one field is wrong and watch the issue list shrink.
String formats in Zod: email, UUID, phone, datetimeEach line prints the format name, the value and whether it passed.
String validation in ZodTry inputs like "ab" or "has space" to see which rule reports an issue.
Type coercion in ZodThe boolean lines print what z.coerce.boolean() returns for each value, including the string "false".
Literal values in ZodAdd "yellow" to the literal array and run again to see it pass.React Hook Form 5 examples · usage and stats
useForm, register and handleSubmit in React Hook FormType into the fields and press Submit: the right panel shows the object your onSubmit callback received.
Required fields in React Hook FormPress Save with the starred fields empty to see both messages, then fill them in and save again.
Email validation with pattern in React Hook FormSubmit an empty field, then something like ada@lovelace, then a full address to see each state.
Custom validation with validate in React Hook FormType admin as the username or an age under 18 and press Create to see the custom messages.
Showing formState errors in React Hook FormPress Check with empty fields, then type a word into Age: the summary on the right lists each failing field and its message.React Hook Form Resolvers 5 examples · usage and stats
Zod validation with zodResolverErrors show on load; type a name and a username of 3+ characters, then press Sign up to see the submitted values.
Number fields with zodResolverThe form validates on load; set age to 18+ and seats to 1+, then press Book.
Schema defaults with zodResolverThe form submits once on load; change the name and press Save to see the defaults added again.
Showing every error with criteriaModeBoth forms validate on load; type a short password in each and press Check to compare the messages.
Resolver options: raw values vs parsed valuesBoth forms submit on load; edit the names and press Submit to compare the two outputs again.Ajv 5 examples · usage and stats
Compiling a schema with AjvAdd a sample such as { foo: "7" } or make bar required and watch which lines turn invalid.
Collecting all errors with AjvFix one field in data at a time and watch the allErrors list shrink while the default count stays at one until everything passes.
One-call validation with ajv.validateRemove the saved.push line and print ajv.errors after the loop to see that only the last result is left.
Reusing schemas with addSchema and $refChange the zip pattern in the address schema once and both home and work addresses follow it.
Custom formats in AjvChange a channel to 300 or a name to start with a digit to see the format error for that field.