chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

Regex Issues #177

Closed cohenerickson closed 8 months ago

cohenerickson commented 10 months ago

input:

model User {
  /// @zod.string.regex(/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-]+)(\.[a-zA-Z]{2,5}){1,2}$/)
  email String 
}

output:

export const UserSchema = z.object({
  /**
   * @([a-zA-Z0-9_\-]+)(\.[a-zA-Z]{2,5}){1,2}$/)
   */
  email: z.string().regex(/^([a-zA-Z0-9_\-\.]+),
})

Using @zod.custom.use with .regex and .refine had the same result

I think it is something to do with the parsing of the '@' character, likely an artifact of '@zod' rule

chrishoermann commented 8 months ago

@cohenerickson this should work now in the latest version 2.7.13 - at least it did with my test schema. Jsut out of curiosity: Is there a reason you do not use the z.string().email() validator?

cohenerickson commented 8 months ago

@cohenerickson this should work now in the latest version 2.7.13 - at least it did with my test schema. Jsut out of curiosity: Is there a reason you do not use the z.string().email() validator?

At first I was unaware that z.string().email() existed so I tried to use a regex to validate it. Once I had discovered that zod did have a built in email validator, I figured I should still create an issue here to document it.