Z
Zod8mo ago
Gludek

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());
...
Jump to solution
6 Replies
Sikari
Sikari8mo ago
I don't see why it wouldn't be able to, nullish just adds undefined | null to the type.
Gludek
GludekOP8mo ago
yeah, but regex validation of .email makes it so it needs to be defined, and null/undefined input is treated as invalid
Gludek
GludekOP8mo ago
No description
No description
Sikari
Sikari8mo ago
Your form most likely is not passing null or undefined, most likely you have ""
Solution
Sikari
Sikari8mo ago
Perhaps you're looking for:
const schema = z.literal("").or(z.string().email());
const schema = z.literal("").or(z.string().email());
Gludek
GludekOP8mo ago
okay that works

Did you find this page helpful?