Skip to content
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 "=" equals sign #3707

Closed
j-christoffersen opened this issue Aug 13, 2024 · 1 comment
Closed

Email validation fails on "=" equals sign #3707

j-christoffersen opened this issue Aug 13, 2024 · 1 comment

Comments

@j-christoffersen
Copy link

j-christoffersen commented Aug 13, 2024

z.string().email() incorrectly marks emails using a = as invalid. = should be valid for the local-part of an email address.

Version: 3.23.8

Testing with the following code:

  // Define email validation schema with Zod
  const zodEmailSchema = z.string().email()

  // Function to validate email using Zod
  function validateWithZod(email: string) {
    console.log(`Testing email: ${email}`)
    try {
      zodEmailSchema.parse(email)
      console.log("Zod: Email is valid")
    } catch (error) {
      console.log("Zod: Email is invalid", error.errors)
    }
  }

  const testEmails = ["[email protected]", "[email protected]"]

  for (const testEmail of testEmails) {
    validateWithZod(testEmail)
  }

Which outputs:

Testing email: [email protected]
Zod: Email is valid
Testing email: [email protected]
Zod: Email is invalid [
  {
    validation: 'email',
    code: 'invalid_string',
    message: 'Invalid email',
    path: []
  }
]
@colinhacks
Copy link
Owner

Email validation has been much discussed in the issues, and this is the current policy: #2157

I'd recommend just using z.string().regex() if you're looking for something more permissive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants