ASP MVC 2: Regular expression attribute working on clientside but not on serverside

Posted by wh0emPah on Stack Overflow See other posts from Stack Overflow or by wh0emPah
Published on 2010-05-02T15:06:17Z Indexed on 2010/05/02 15:57 UTC
Read the original article Hit count: 295

Filed under:
|
|
|
[Required(ErrorMessage = "Date is required")]
[RegularExpression(@"^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$", ErrorMessage="Date is not valid must be like (dd/mm/jjjj)")]
public DateTime Startdate{ get; set;}

The client-side validation works perfectly. So it seems that JavaScript can successfully understand my regular expression. But when I do a postback, and the modelstate.Isvalid() gets called.

My date isn't valid anymore. So I'm guessing that when .NET performs the matching with the regEx it doesn't match.

My question: Why does this regular expression match on the client side but not on the server side?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about c#