For a project at work our API uses ULIDs. I noticed Zod comes with a ULID validator built in, however, it always marks our ULIDs as invalid. After a short investigation, I learned that only uppercase ULIDs are considered valid by Zod.
I think the regex Zod uses to check ULID validity, should also allow lowercase ULIDs (or even mix of upper and lower case) as the ULID spec indicates they are case insensitive.
The simple workaround we use right now is z.string().toUpperCase().ulid() (we used to use refine() and a custom validation function), but imo it's not ideal as it affects other validation checks and it might be confusing to other users why lowercase ULIDs are considered invalid. wdyt?
I don't mind working on this myself, as I believe it's just updating the regex to be case insensitive and making sure tests still succeed.
Hello everyone.
For a project at work our API uses ULIDs. I noticed Zod comes with a ULID validator built in, however, it always marks our ULIDs as invalid. After a short investigation, I learned that only uppercase ULIDs are considered valid by Zod.
I think the regex Zod uses to check ULID validity, should also allow lowercase ULIDs (or even mix of upper and lower case) as the ULID spec indicates they are case insensitive.
The simple workaround we use right now is
z.string().toUpperCase().ulid()
(we used to userefine()
and a custom validation function), but imo it's not ideal as it affects other validation checks and it might be confusing to other users why lowercase ULIDs are considered invalid. wdyt?I don't mind working on this myself, as I believe it's just updating the regex to be case insensitive and making sure tests still succeed.