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

EmailAttribute should allow null values #41

Closed
alexrp opened this issue Dec 25, 2022 · 2 comments
Closed

EmailAttribute should allow null values #41

alexrp opened this issue Dec 25, 2022 · 2 comments

Comments

@alexrp
Copy link

alexrp commented Dec 25, 2022

Specifically:

if (value == null)
return new ValidationResult ("Email can't be null", memberNames);

return value != null && EmailValidator.Validate ((string) value, AllowTopLevelDomains, AllowInternational);


Most (all?) attributes in System.ComponentModel.DataAnnotations of a similar nature to EmailAttribute consider null to be valid.

Examples:

Generally speaking, one should use RequiredAttribute if a value should not be allowed to be null. (Higher-level frameworks like ASP.NET Core will additionally use C# nullability annotations to infer RequiredAttribute.)

@alexrp
Copy link
Author

alexrp commented Dec 25, 2022

(Aside: The allocation of memberNames is pointless in the success case.)

jstedfast added a commit that referenced this issue Dec 28, 2022
@jstedfast
Copy link
Owner

Seems reasonable. Hopefully won't break any existing apps due to a change in expectations.

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