I have tried to follow guidelines found by Googling for validating email addresses, and used the following:
[Required(ErrorMessage = "Email required.")]
[ValidateEmail(ErrorMessage = "Valid email required.")]
public string Email { get; set; }
And this is the attribute class:
public class ValidateEmailAttribute : RegularExpressionAttribute
{
public ValidateEmailAttribute() :
base(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$") {}
}
Also found Googling for examples.
However, I tried this version of an email attribute and another one, but neither stops me from entering whatever in the email field. I tried just entering a simple name, with spaces and all, and it went through just fine!
Why isn't it kicking in and stopping this? The Required attribute works, it's just the regex one that doesn't.