I have the following presentation model.
public UserViewModel { ... [Email(@"^ .+@ [^\.].*\.[az]{2,}$", false, ErrorMessage="...")] public string EmailAddress{ get; set; } ... } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Visitor(UserViewModel userViewModel) ...
However, I found that sometimes the user copies and pastes the email into the view from another mailbox, text document, etc., and sometimes it captures the leading and / or ending space. Since users are not the most intelligent, and spaces are not displayed in the input control, then I must ignore them and continue.
So if my model state is invalid, I wonder how best to solve this -
- Add spaces to my expression for verification.
- In the action result method, check if you delete the email address and remove the error from the model state manually.
- Do something else ...
I'm not 100% sure about 1, and 2 is honest too!
Rippo source share