Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
13 replies
O2K

Ensure uniqueness for zod schema field

Hello!
I am using react-hook-form and have the following zod object to validate the input participants:

z.object({
            email: z // Should be unique (not same as any other participant.email)
              .string()
              .email({
                message: tParticipant("fields.email.rules.pattern"),
              })
              .min(1, {
                message: tParticipant("fields.email.rules.required"),
              }),
            name: z // Should be unique (not same as any other participant.name)
              .string()
              .min(1, { message: tParticipant("fields.name.rules.required") })
          })
          .array()


How can I validate using Zod that each email is unique, aswell as each name ? Something like a .unique() is what I am looking for 🙂

Thank you!
Was this page helpful?