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 rejects email with special characters #2205

Open
timheerwagen opened this issue Mar 17, 2023 · 5 comments
Open

Email validation rejects email with special characters #2205

timheerwagen opened this issue Mar 17, 2023 · 5 comments

Comments

@timheerwagen
Copy link

For example info@räucher.de gets rejected because of the "ä".

In Chrome, special characters are automatically converted to ASCII on the client side and back. However, this is not the case with Firefox and Safari. So I have no problems in Chrome browsers, but in the others.

Im using simple z.string().email(), dont want to transform each to ASCII by myself and use my own validator.

@MerlinMason
Copy link

MerlinMason commented Mar 17, 2023

On the subject of email regexs...
I've spotted an issue with email validation if

  1. there's a subdomain
  2. the domain is hyphenated
const a = z.string().email();
a.parse("yo@subdomain.my-domain.com");

returns

ZodError: [
  {
    "validation": "email",
    "code": "invalid_string",
    "message": "Invalid email",
    "path": []
  }
]

Using Zod 3.21.4

Edit - looks like there's a possible fix proposed #2157

@timheerwagen
Copy link
Author

This is my current workaround:

import { z } from "zod";
import punycode from "punycode";

export const zEmail = z
  .string()
  .transform(punycode.toASCII)
  .pipe(z.string().email());

@stale
Copy link

stale bot commented Jun 19, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@kasbah
Copy link

kasbah commented Jul 7, 2023

Emails with special characters still get rejected.

@Soviut
Copy link

Soviut commented Oct 31, 2023

EDIT: I just updated to latest (3.22.4) and that fixed this.

I have a similar issue with emails that contain multiple subdomains with the first level subdomain (closest to the domain) containing numbers.

zod@3.21.4

PASS test@example.com
PASS test@test.example.com
PASS test@test0.example.com
PASS test@test.test.example.com
PASS test@test0.test.example.com

FAIL test@test.test0.example.com
FAIL test@test.test.test0.example.com
FAIL test@test.test0.test.example.com

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

4 participants