Overview
Thez.email() function creates a schema that validates email addresses according to a relaxed RFC 5322 standard.
~/workspace/source/packages/zod/src/v4/classic/schemas.ts:455
Basic Usage
Validation Rules
The email validator accepts a wide range of valid email formats:Valid Email Formats
- Standard format:
[email protected] - With dots:
[email protected] - Subdomains:
[email protected] - Plus addressing:
[email protected] - Numbers:
[email protected] - Hyphens in domain:
[email protected] - Underscores:
[email protected] - Multiple TLDs:
[email protected] - Hyphens in local part:
[email protected] - Single character:
[email protected] - Short domains:
[email protected]
Invalid Email Formats
The validator rejects:- Missing domain:
@domain.com - Missing @ symbol:
email.domain.com - Multiple @ symbols:
email@[email protected] - Leading/trailing dots:
[email protected],[email protected] - Consecutive dots:
[email protected] - Invalid domain:
email@domain - Domain starting with hyphen:
[email protected] - Non-ASCII characters:
あいうえお@domain.com - Quoted strings:
"email"@domain.com(not supported) - IP addresses:
[email protected](not supported) - IPv6 addresses:
email@[IPv6:...](not supported)
Examples
Basic Validation
Custom Error Message
Combining with Other Validations
In Object Schemas
Parameters
Theemail() function accepts an optional parameter:
string: Custom error messageEmailParams: Object with:message?: string: Custom error message
Return Type
Returns aZodEmail schema that validates and returns strings.
The email validator uses a practical implementation that balances correctness with usability. It does not support all technically valid RFC 5322 formats (like quoted strings or IP addresses) to avoid common security issues and edge cases.
Related Methods
- z.string() - Base string validation
- z.url() - URL validation