-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Email validation fails on ampersand "&" sign #3411
Comments
It looks like this was supported at one point. But it was removed. |
Per #2157 Zod implements "Gmail rules" by default for email address validation. You can use const emailRegex =
/^(?!\.)(?!.*\.\.)([A-Z0-9_'+-\.]*)[A-Z0-9_'+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
const emailSchema = z.string().superRefine((data, ctx) => {
if (!emailRegex.test(data)) {
ctx.addIssue({
code: z.ZodIssueCode.invalid_string,
message: "Invalid email address",
validation: "email",
});
}
}); |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
I noticed the z.string().email() fails when the email contains an ampersand sign. This should be allowed.
Example:
z.string().email().parse("test&[email protected]")
The text was updated successfully, but these errors were encountered: