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

Did you find this page helpful?