-
email: z.email("Invalid email format").string().trim().toLowerCase(),And, if I hover function email(params?: string | {
abort?: boolean | undefined;
pattern?: RegExp | undefined;
error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueInvalidStringFormat>> | undefined;
message?: string | undefined | undefined;
} | undefined): z.ZodEmail
email: z.string().trim().toLowerCase().email("Invalid email format"),And, if I hover (method) ZodString.email(params?: string | {
abort?: boolean | undefined;
pattern?: RegExp | undefined;
error?: string | z.core.$ZodErrorMap<z.core.$ZodIssueInvalidStringFormat> | undefined;
message?: string | undefined | undefined;
} | undefined): z.ZodString
@deprecated — Use z.email() instead.For context, I was trying out zod validation for my auth route, and this is from import * as z from "zod";
const SignUpSchema = z.object({
name: z
.string()
.min(2, "Name must be at least 2 characters")
.max(50, "Name cannot be more than 50 characters")
.trim(),
email: z.string().trim().toLowerCase().email("Invalid email format"),
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi @codayon! I'm Dosu and I’m helping the zod team. This is expected in Zod v4: the chainable If you want to combine string transformations (like z.string().trim().toLowerCase().pipe(z.email())or z.preprocess(val => val.trim(), z.email().toLowerCase())This approach preserves transformation order and uses the new Let me know if this answers your question—feel free to close the issue if you're all set! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Hi @codayon! I'm Dosu and I’m helping the zod team.
This is expected in Zod v4: the chainable
.email()method onz.string()is deprecated and will show a warning, while the top-levelz.email()function is the new, preferred way to validate emails and does not show a deprecation warning. This change was made because string format validations like email, uuid, etc., are now represented as specialized subclasses (likeZodEmail) and exposed as top-level factory functions for better tree-shaking and API clarity. The old method form (z.string().email()) still works but is marked as deprecated in TypeScript/JSDoc to encourage migration to the new API (changelog, docs).If you want to combine st…