-
Notifications
You must be signed in to change notification settings - Fork 5k
Better email address attribute #27592
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
Comments
This is a pretty difficult problem to solve, and I don't think that a (very complicated) regex is the answer. In System.Uri we implement email address parsing that isn't perfect but that is generally "good enough", and I think we should take the same approach here. Are you actually running into issues caused by these specific cases? |
I ran into issues with this too, see my my comments here: https://github.com/dotnet/corefx/issues/32688#issuecomment-428780729 |
@chrisaut I totally agree. EmailAddressAttribute is useless now. @rmkerr Our tester found out this. For him, it is unacceptable that he can register a user with an invalid email address. And for me, it is not "good enough". Even in spring they use regex for it (https://github.com/Baeldung/spring-security-registration/blob/master/src/main/java/org/baeldung/validation/EmailValidator.java) If it is that difficult problem maybe you should remove this attribute? |
@galczo5 You do realise that the expression used in your linked file is not correct aka. RFC compliant? |
@2called-chaos For me, if we want to keep it regex free, we should implement additional email address domain checking and it will be great. We should make very good documentation for it. |
Hi, |
IMHO the safest way to validate an email address is to actually send an email and verify it came through. |
@conradreuter, agreed. But in most cases you want to verify it without sending an email, that's what the old RegEx was for. Why not use it again? |
That highly depends on what you specify the word "valid" to mean. If you want to make sure that the address conforms to RFC2822, then sure, a complex RegEx might be the way to go. But for all practical purposes I can think of, "valid" means that somebody is actually able to receive an email via this address. A quick sanity check à la contains @ and something before and after might be completely sufficient. |
@conradreuter I agree that simple check is ok, but current validation is not enough. A user can misspell an email address: instead of "user@user.com", the user types "user@userLcom" and it is a problem. |
If I'm not mistaken, according to RFC2822 this is a valid email address. (Just like root@localhost is a valid email address) |
Speaking on this point, I've had multiple sites reject my primary email address as "invalid". (Including one unsubscribe box, which is a quick way to get marked as spam) |
Maybe EmailAddressAttribute should implement more than one validation algorithm. |
I think we can simply have a better implementation without RegEx (for security reason dotnet/corefx#4319). On codebase there is already similar code. |
This is not something we plan to implement. The check is intentionally naive because doing something infallible is very hard. The email really should be validated in some other way, such as through an email confirmation flow where an email is actually sent. The validation attribute is designed only to catch egregiously wrong values such as for a U.I. |
This commit introduces modes in Email rule. Previous logic is triggered in "ComplexRegex" mode, which is still set as the default option. "DataAnnotationsCompatible" mode validates email in the very simple way, exactly the same as in System.ComponentModel.DataAnnotations.EmailAddressAttribute The reason behind such simple logic: dotnet/runtime#27592 (comment)
Hi,
Today I found out that EmailAddressAttribute is quite bad.
First of all, now email string can contain only one @ char.
RFC 2821 specifies Abc@def@example.com as valid address (https://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/), so I think that we need better validation.
Second, mail address mail@.com is not valid, but EmailAddressAttribute recognizes it as valid.
I've prepared some tests (dotnet/corefx#32717).
Can we solve it with regular expressions? I can provide new implementation in next few days.
The text was updated successfully, but these errors were encountered: