Validation Pattern
Validate user input with Zod for type-safe, reusable validation schemas that work on both client and server.
What's Included#
- Common reusable schemas for emails, passwords, usernames, URLs, and phone numbers
- Form validation schemas for auth flows (login, register, reset password)
- API input validation with pagination, search, and CRUD schemas
- Validation helper with API route wrapper for consistent error responses
- Custom async validators for uniqueness checks and database existence
- Environment variable validation with typed config at startup
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the validation pattern from Bootspring"
- "Apply the Bootspring validation pattern to my project"
Key Considerations#
- Always validate on the server; never trust client-side validation alone
- Use safeParse instead of parse to handle errors gracefully without throwing
- Provide user-friendly custom error messages for every validation rule
- Use z.infer to derive TypeScript types from schemas and avoid duplication
- Use .transform() to normalize input data like trimming strings and lowercasing emails
Related Patterns#
- Forms - Form handling with validation
- Error Handling - Error display and handling
- Date Handling - Date validation schemas