Semicolon separated emails using drizzle-zod.

I have the following Schema definition for drizzle-zod:
export const RegistroSchema = createSelectSchema(registro, {
correo: (schema) => schema.correo.email(),
retencionRenta: (schema) => schema.retencionRenta.optional(),
retencionIVA: (schema) => schema.retencionIVA.optional()
});
export const RegistroSchema = createSelectSchema(registro, {
correo: (schema) => schema.correo.email(),
retencionRenta: (schema) => schema.retencionRenta.optional(),
retencionIVA: (schema) => schema.retencionIVA.optional()
});
I want to change the email verification from a single to a multi email verification I have an idea of the required zod definition
z.object({
factoryEmail: z
.string()
.refine((emailValue) => emailValue.split(";").every((item) => z.string().email().safeParse(item).success)),
});
z.object({
factoryEmail: z
.string()
.refine((emailValue) => emailValue.split(";").every((item) => z.string().email().safeParse(item).success)),
});
but I am not sure how to represent that inside ResitroShema (for the field: correo)?
1 Reply
Ben Quan
Ben QuanOP3w ago
Answering my own question:
correo: (schema) =>
schema.correo.refine((emailValue) =>
emailValue.split(';').every((item) => z.string().trim().email().safeParse(item).success)
),
correo: (schema) =>
schema.correo.refine((emailValue) =>
emailValue.split(';').every((item) => z.string().trim().email().safeParse(item).success)
),
Want results from more Discord servers?
Add your server