Date Validation in ASP.NET

Posted January 28th 2005 by Matt Berther

Ever have the need for a user to enter a date into a textbox, but not sure how to validate that they actually did?

<asp:CompareValidator id="dateValidator" runat="server" 
  Type="Date" Operator="DataTypeCheck" ControlToValidate="dateTextbox" 
  ErrorMessage="Please enter a valid date.">
</asp:CompareValidator>

This beats the heck out of writing my own code to do this, and surely this is better tested as well. ;)

blog comments powered by Disqus