Zod date string validation
Someone that knows how I can use datetime string validation in zod but only require the year month and day and not the time?
Do I need to write my own regex validation for it instead?
8 Replies
using
z.coerce.date()
can fix that no ?
okey and it would then fail if I sent in something that isn't a substring of datetime?
as long as the value works with
new Date(value)
it will pass
after the value is valid
you can correct_value.toISOString()
if you wantHow should it then look in my schema?
This is how it currently looks
bought: z.coerce.date({...})
If you want the string version of the date, then you can parse laterMaybe it would be cleaner to just add regex for it instead?
Something like this?
const isIsoDate = /\d{4}-[01]\d-[0-3]\d/;
i mean
if you want to
then I don't have to both parse and coerce it