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!
you can change the setters to have the trim code upon setting the value in the property too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With