You can verify the user input in the ASP. NET webpage against a specific data type to ensure that the user inputs numbers, dates, and so on. For example, to collect birthdate information on the user registration page, you can use the comparevalidator control to ensure that the date format of the page is recognizable before submission.
1. Add the comparevalidator control to the page and set the following attributes:
Attribute |
Description |
Controltovalidate |
The ID of the control whose data type you want to check. |
Errormessage, text, display |
These attributes specify the text and location of errors to be displayed when verification fails. |
2. Set the following attributes to set the data type to be compared:
Attribute |
Description |
Type |
The data type to be checked. Type is specified by the validationdatatype enumeration. This enumeration allows you to use type names such as string, integer, double, date, and currency. |
Operator |
Datatypecheck |
Note: If you leave the control blank, the control passes comparative verification. To force the user to enter a value, add the requiredfieldvalidator control.
3. Add a test in ASP. NET webpage code to check the validity.