+1  A: 

Suppose the user enters 06/27/2010 in the text field and submits the form.

  1. The default model binder runs and tries to bind what the user entered to your model. The BirthDate property is of type DateTime and as you know this type contains an hour part. So now BirthDate = 6/27/2010 12:00:00 AM

  2. Validation kicks in next. The BirthDate property is decorated with the RegularExpression attribute so the IsValid method is called with the string value of 6/27/2010 12:00:00 AM which fails against your pattern.

  3. The corresponding error message is shown to the user.

So the usage of this regular expression attribute is questionable. RegularExpressionAttribute works fine with string properties though.

If the user enters an invalid date the model binder will protest anyway much before the validation happens. It will also check for invalid days and months which your regular expression doesn't.

Darin Dimitrov
Yes, however I also tried this with the "Date" field in the database which doesn't expect a time field. Is there a better way to validate the input?
rockinthesixstring
There's no relation between the type you are using to store the field in the database and the model binding.
Darin Dimitrov
I updated my question a little bit. Wondering about modifying the ModelState Item before it's passed to IsValid.
rockinthesixstring
Or are you saying I should just leave it and let the model binder handle it? the only problem with that is that there's no client side validation happening.
rockinthesixstring