fastify-type-provider-zod
fastify-type-provider-zod copied to clipboard
Can't find regex on z.string
I get Property 'regex' does not exist on type 'ZodEffects<ZodString, string, string>'
I define the z.strng like this:
z.string({
required_error: 'Username is required',
invalid_type_error: 'Name must be a string',
})
.refine(
(data: string) => data.length > 0,
(val: string) => ({
message: 'Username cannot be empty',
}),
)
.regex(/^[a-zA-Z0-9]+$/, {
message: 'Username can only contain alphanumeric characters',
})
.min(3, {message: 'Username must be at least 3 characters long'})
.max(20, {message: 'Username cannot exceed 20 characters'})
Could this be because the zod version of the library is outdated? Locally I have zod version 3.23.8
might be. I'll try to release the updated version this week
Can you please try 1.2.0?
I think you should put regex before refine