Zod

Z

Zod

Join the community to ask questions about Zod and get answers from other members.

Join

ménard - I'm thinking of something like:typesc...

Hi, is there a way without going out of band to make one field always have the same value as another even when it's not part of the input object? I'm thinking of something like: ```typescript const vpm = z.object({...

Haddok - Hi everyone , i have to use zod in my ...

Hi everyone , i have to use zod in my javascript environment i have defined a schema , that has multiple fields the entire schema validation works perfectly , but for javascript i am not sure how to use ...
Solution:
Hi there , thank you for your answer So basically i have a schema like this ```js ...

doug4794 - I have this login schema and want to...

I have this login schema and want to display my own error message. ```ts export const loginSchema = z.object({ password: z.string().min(8, { message: i18n("errors.password-too-short") }),...

Luan Mário - how to make an input of type date ...

how to make an input of type date optional?

QBit - Form should not accept decimal nos. For...

Form should not accept decimal nos. For <=0 numbers code is written to not accept them. Now it accepting positive decimal also but I don't want. What to do? ```ts "use client" ...
Solution:
found the solution
ID: z.coerce.number().int().positive().finite()
ID: z.coerce.number().int().positive().finite()
...

Bence (Arzen) - Hey guys 🙂I have a (might be)...

Hey guys 🙂 I have a (might be) silly question. I have a schema exported as module: ```ts // schema.ts...

Gludek - Hey,I have objects like this (there's...

Hey, I have objects like this (there's little bit more nesting), but for some reason the superRefine doesn't trigger for guardian's BaseData, only for the patient ```js const baseData = z .object({...

adxvcasas - How to set a default value for opti...

How to set a default value for optional values? Hello, so I'm trying to set a default value for my schema, is this approach acceptable? ```...

Gludek - Just to confirm z.string().email() can...

Just to confirm z.string().email() can't be combined with .nullish() right?
Solution:
Perhaps you're looking for:
const schema = z.literal("").or(z.string().email());
const schema = z.literal("").or(z.string().email());
...

adxvcasas - Hello, so right now I have checkbox...

Hello, so right now I have checkbox wherein I can store multiple strings inside an array, but the problem i'm encountering right now is when I'm storing it to my database mysql using prisma orm , I get a warning of Field "doesHaveTCETAssitance" in model "AppoinmentSchedule" can't be a list. The current connector does not support lists of primitive types.Prisma, because I set doesHaveTCETAssitance to doesHaveTCETAssitance String[] which is not supported by prisma mysql. ```...

shadi - hey everyone, i've been struggling with...

hey everyone, i've been struggling with building a recursive zod schema. I tried following the docs: https://github.com/colinhacks/zod?tab=readme-ov-file#recursive-types but still can't figure it out for my use case. here is what I'm trying to achieve: ```ts const BranchSchema = z.object({ prompt: BranchPromptSchema, // regular object schema...
Solution:
You have to manually type either direction of the types, for example: ```ts const ActionSchema = z.object({ ... }); const BranchPromptSchema = z.object({ ... });...

squibler. - Hi folks. I'm looking to validate a...

Hi folks. I'm looking to validate that a user input is not in a blacklist - like for example swear words. Enum does this for allowed strings, but I'm struggling to find something that will work for disallowed strings. I have tried a regex - but my datasource has over 2000 disallowed words and regex would be too slow. Basically I'm looking for something like:...
Solution:
Using this now: ```ts import { blacklist } from '~/blacklist'; export const notBlacklisted = (input: string): boolean => {...