This tutorial shows how you can validate the input of users using ASP.NET and C#

This tutorial shows how the ASP.NET tools make it easy for you to validate user input, both client-side and server-side.

First we add the form elements from the Toolbox, including the RequiredFieldValidator, RegularExpressionValidator and the ValidationSummary.
Note the CustomValidator control, which allows us to create a custom rule for validation. This particular one checks to see if a date is in the correct format:

In the code-behind file we have the following:

For client-side validation of the date field, we can use a bit of JavaScript:
Note: For this to work, the ‘EnableClientScript’ Property of the CustomValidator has to be set to True.M/em>

Download Source Files