This project is read-only.


Oct 4, 2010 at 9:47 AM

In one of our entities we use the EmailValidator to validate well ehh the email address :-)

The validation works correct when you enter an incorrect email address, however after emptying the value the error for an incorrect email address keeps showing up. Adding an entity without entering an email address works as expected: an empty string is correct.

Oct 4, 2010 at 10:34 AM
Edited Oct 4, 2010 at 10:36 AM

Hi nuub.

The EmailValidator competence is just to ensure the email is well formatted, but maybe there are some classes where the email field is optional, and other ones where it's mandatory to fill it. So, as EmailValidator doesn't know what scenario is managing, the competence for the non-nullable fields is for other validators, in this case for the StringLengthValidator (as the email field is a string, in other case it would be a NotNullValidator).

If we want the email field to be mandatory we'll write something like this:

string email;

[StringLengthValidator(AllowNulls = false), EMailValidator]

public string Email;



The reason to use StringLengthValidator instead NotNullValidator is because the collusion between string.Empty and "", that makes the empty fields undistinguishable in DB, so for the not nullable string fields we'll use the first, and for all the other types we'll use the second.


Hope it helps.