jstedfast / EmailValidation

A simple (but correct) .NET class for validating email addresses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`EmailAttribute` should allow null values

alexrp opened this issue · comments

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.)

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

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