Input validation
Validate an email field in a request, form, or configuration object.
Zod · Module
z.email() creates a schema for validating email addresses. It uses a comparatively strict default pattern and accepts a custom pattern regular expression for alternative rules.
z.email() creates a Zod schema that checks whether input is an email address. Its default validator is comparatively strict; pass an options object with pattern when an application needs a different supported or custom regular expression.
z.email(options?)| Name | Type | Description |
|---|---|---|
options | object | Optional configuration object; its pattern property supplies the regular expression used for email validation. |
pattern | RegExp | Regular expression used to customize email validation behavior. |
A Zod email schema that validates input strings against the selected email regular expression.
z.email() to create a schema specifically for email-address validation.pattern option.z.regexes.email represents the same default email pattern and can be passed explicitly.z.regexes.unicodeEmail when a looser pattern that permits Unicode addresses is appropriate.z.email() form; the older chained method remains available but is deprecated.import { z } from "zod";
const Contact = z.object({
email: z.email({ pattern: z.regexes.html5Email }),
});
console.log(Contact.parse({ email: "dev@example.com" }));
Creates an object schema whose email field accepts a valid HTML5-style email address.
Validate an email field in a request, form, or configuration object.
Apply HTML5-compatible address rules.
Permit internationalized email addresses.
Enforce application-specific address syntax.
Use z.email() to construct an email-validation schema, then parse input with the normal Zod parsing APIs. By default, it applies a comparatively strict regular expression for common email addresses.
Follow-up: How would you support a different email convention? Pass a custom regular expression through the pattern option, or select one of Zod’s exported regexes.
Pass an options object containing pattern, such as z.email({ pattern: z.regexes.html5Email }). This replaces the default matching behavior with the supplied regular expression.
Follow-up: Which built-in patterns are available? The documentation lists the default email regex, HTML5 email, RFC 5322-style, and Unicode-oriented patterns.
z.email() instead of z.string().email()?The current API is the top-level z.email() function. Although z.string().email() still works, the documentation marks method forms as deprecated and says top-level string formats are more tree-shakable.
Follow-up: What migration should a codebase make? Replace chained .email() calls with z.email() while preserving surrounding object, optionality, or array composition.
z.regexes.emailz.regexes.html5Emailz.regexes.rfc5322Emailz.regexes.unicodeEmailz.string().email()