-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Able to validate invalid email #1979
Comments
Are you able to give a code example? |
const scheme = z.string().email();
const email = "pawan.anand@%9y8325&%#%$&#$R%&#$%R&#$%R&%#$R%%^^%5rw3ewe.r.ef.d.d.d.d.d.aaaa.wef.co";
scheme.parse(email); //don't throw an error According to this site (link) the domain can contains:
|
Behind the scenes zod uses this regex to validate email addresses: Lines 523 to 524 in a57fc2d
If you would like a different regex to do this, you can use something like these: // completely custom regex
const schema = z.string().regex( /some regex/ )
// custom regex that must match the zod email regex
const schema = z.string().email().regex( /some regex/ ) |
I created a pull request and for me this is a valid change because can prevent some issues |
* Increment email validation Supported: - local-part -> Dot-string / Quoted-string - domain -> latin letters, numbers, "-" / IPv4 address Unsupported: - domain -> IPv6 * Fix import type in some test files The error generated is: TS2307: Cannot find module '@jest/globals' or its corresponding type declarations. * Format code with prettier config * Add more IPv4 test * Add Invalid IPv4 tests * Fix tests * Lint fix --------- Co-authored-by: Colin McDonnell <colinmcd94@gmail.com> Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
Another example of email that works but, I believe, is invalid: |
This doesn't pass the test for the default regex. |
I disagree. const schema = z.string().email()
console.log( schema.safeParse( 'invalid@foo.....com' ).success ) // true |
Currently, I'm able to pass this as email and get no issues.
The text was updated successfully, but these errors were encountered: