zod
zod copied to clipboard
Update email regex to use W3C's one?
There is no 100% bullet proof email regex, but should you update it to use W3C's one? Currently I'm facing a bug that a\[email protected]
is passed, when W3C's regex wouldn't pass it.
Current zod regex for email is:
(/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i)
When W3C suggests:
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
See also: https://github.com/colinhacks/zod/pull/1435
@Tyler-Murphy PR #1435 does not fix this issue. With those changes a\[email protected]
is still marked as "valid"... yeah, I know there are no bullet-proof regex, but your changes doesn't help this issue.
Sorry, I should have been clearer. I'm just pointing out its existence, since the W3C regex appears not to work with some of the test cases in #1435.
This would also allow +
in addresses like [email protected], which would be good.
@timojuonoja "\" is not valid email character, the only way to use it is with the double quotes around the local-part of email
@timojuonoja "" is not valid email character, the only way to use it is with the double quotes around the local-part of email
Yes, you are absolutely right by the way. We seem to have an error in our test cases after all... I'm closing this due to incorrect assumptions.