Skip to main content

Overview

The z.email() function creates a schema that validates email addresses according to a relaxed RFC 5322 standard.
import { z } from "zod";

const emailSchema = z.email();
Location in source: ~/workspace/source/packages/zod/src/v4/classic/schemas.ts:455

Basic Usage

const emailSchema = z.email();

emailSchema.parse("[email protected]"); // ✓ passes
emailSchema.parse("invalid@"); // ✗ throws ZodError

Validation Rules

The email validator accepts a wide range of valid email formats:

Valid Email Formats

Invalid Email Formats

The validator rejects:

Examples

Basic Validation

const schema = z.email();

schema.parse("[email protected]"); // ✓ passes
schema.parse("[email protected]"); // ✓ passes
schema.parse("invalid@"); // ✗ throws

Custom Error Message

const schema = z.email("Please enter a valid email address");

const result = schema.safeParse("invalid-email");
if (!result.success) {
  console.log(result.error.issues[0].message);
  // "Please enter a valid email address"
}

Combining with Other Validations

const schema = z.email()
  .min(10, "Email must be at least 10 characters")
  .max(100, "Email must not exceed 100 characters")
  .toLowerCase();

schema.parse("[email protected]"); // ✗ fails min length check
schema.parse("[email protected]"); // ✓ passes and converts to lowercase

In Object Schemas

const userSchema = z.object({
  email: z.email(),
  name: z.string(),
});

userSchema.parse({
  email: "[email protected]",
  name: "John Doe"
}); // ✓ passes

Parameters

The email() function accepts an optional parameter:
z.email(params?: string | EmailParams)
  • string: Custom error message
  • EmailParams: Object with:
    • message?: string: Custom error message

Return Type

Returns a ZodEmail schema that validates and returns strings.
type Output = string;
type Input = string;
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.

Build docs developers (and LLMs) love