Reputation: 22424
I have the following view model.
public UserViewModel {
...
[Email(@"^.+@[^\.].*\.[a-z]{2,}$", false, ErrorMessage="...")]
public string EmailAddress{ get; set; }
...
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Visitor(UserViewModel userViewModel)
...
However I have found that sometimes a user copies and pastes an email into the view from another email, word document etc and sometimes it picks up a leading and/or trailing space. As users are not the most intelligent and spaces do not show in the input control then really I should ignore these and carry on.
So if my model state is invalid, I am wondering the best approach to resolve this-
I am not 100% sure about 1, nor 2 too be honest!
Upvotes: 6
Views: 3324
Reputation: 1517
you can change the setters to have the trim code upon setting the value in the property too.
Upvotes: 1