ASP MVC 2: Regular expression attribute working on clientside but not on serverside
- by wh0emPah
[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?