I've got an Html.TextBoxFor element where a user can enter their birthdate. I want to make sure they only enter a date that is older than today's date. Here is the validation I have in my model:
[Required(ErrorMessage = "Birthdate is required")]
[RegularExpression(@"^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$", ErrorMessage = "Please use MM/DD/YYYY")]
[DataType(DataType.Date)]
public System.DateTime Dob { get; set; }
and here is the relevant part of my view:
<td>
@Html.Label("DOB:")
@Html.TextBoxFor(m => m.Driver.Dob, "{0:dd/MM/yyyy}")
@Html.ValidationMessageFor(m => m.Driver.Dob)
</td>
Is there a built-in way offered by .net to do this?