colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

The above code how to verify whether newPwd and confirmPwd are consistent, and can get a custom message when the verification fails, just like two passwords are inconsistent; Just like if this check doesn't pass, it gets it in errors.message #3702

Open wangzhipeng-vicky opened 1 month ago

wangzhipeng-vicky commented 1 month ago

export const zr_colorsize_reset_pwd_FormScheme = z .object({ oldPwd: z.string().min(8, { message: "8+ characters required" }).trim(), newPwd: z.string().min(8, { message: "1+ characters required" }).trim(), confirmPwd: z .string() .min(8, { message: "4+ characters required" }) .trim() }) The above code how to verify whether newPwd and confirmPwd are consistent, and can get a custom message when the verification fails, just like two passwords are inconsistent; Just like if this check doesn't pass, it gets it in errors.message .min(8, { message: "4+ characters required" })

sunnylost commented 2 weeks ago

You should check out refine

wangzhipeng-vicky commented 1 week ago

I used refine, and if the validation fails and I can't retrieve the message, as in my code below what should I do export const zr_colorsize_reset_pwd_FormScheme = z.object({ oldPwd: z.string().min(8, { message: "8+ characters required" }).trim(), newPwd: z.string().min(8, { message: "8+ characters required" }).trim(), confirmPwd: z.string().min(8, { message: "8+ characters required" }).trim(), })