Kevin Powell - CommunityKP-C
Kevin Powell - Communityโ€ข6mo agoโ€ข
76 replies
chikanlegbees

how to go about email validation with zod?

im trying to validate emails with zod and have errors for when its required and invalid for example
z
.object({
email: z.email({
required_error: "Email is required.",
invalid_type_error: "Email is invalid.",
}),


this is what im doing currently but i dont get this to show the required error when the field is blank! what am i messing up? ive looked into the docs but cant get to see the issue ๐Ÿ™

in the zod docs we have this

so i tried doing

 z
    .object({
      email: z.email({
        error: (issue) =>
          issue.input === undefined ? "Email is required" : "Invalid email",
      }),


but i still get the latter error instead of email is required ๐Ÿ™
Was this page helpful?