I have the following ViewModel, it has a data annotation to validate the email and a regular expression to make sure the email is in lower-case and without spaces.
[Required]
[MaxLength(200)]
[EmailAddress]
[RegularExpression(@"^[a-z0-9\-_\.\@\:]+$", ErrorMessage = "Characters are not allowed.")]
public string Email { get; set; }
For example:
- "test@hotmail.com" = OK
- " test@hotmail.com" = NOT OK
- "TEst@hotmail.com" = NOT OK
- "test@hotmail.com " = NOT OK
I can get the upper-case error but not the space error.
However, if I comment [EmailAddress]
I can get both errors, upper-case and space.