Zod type email string and number message not working correctly

Hey guys i am facing a issue i am also new to typescript
const authschem = z.object({
email: z.union([
z.string().email({ message: "Please enter a valid email address" }),
z.number()
.min(10, { message: "Invalid number" })
.max(10, { message: "Invalid number" }),
]),
password: z.string(),
});
const authschem = z.object({
email: z.union([
z.string().email({ message: "Please enter a valid email address" }),
z.number()
.min(10, { message: "Invalid number" })
.max(10, { message: "Invalid number" }),
]),
password: z.string(),
});
i am using this type for react-hooks-forms and i want the email to either be string or number and when it is number show Invalid number message and when incorrect email message but it is only showing email message everytime how can i achive something like this
2 Replies
ayush_uidev
ayush_uidevOP2y ago
prakhar_goel
prakhar_goel2y ago
if input type is text you will phone number in string format you need to convert it transform it to a number before checking it
Want results from more Discord servers?
Add your server