Types of Validation for ASP.NET Server Controls
The following table lists the types of validation controls available and how you can use them.
Security Note By default, the Web Forms page automatically validates that malicious users are not attempting to send script to your application. For more information, see Scripting Exploits.
|Type of validation||Control to use||Description|
|Required entry||RequiredFieldValidator||Ensures that the user does not skip an entry.|
|Comparison to a value||CompareValidator||Compares a user's entry against a constant value, or against a property value of another control, using a comparison operator (less than, equal, greater than, and so on).|
|Range checking||RangeValidator||Checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates.|
|Pattern matching||RegularExpressionValidator||Checks that the entry matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in social security numbers, e-mail addresses, telephone numbers, postal codes, and so on.|
|User-defined||CustomValidator||Checks the user's entry using validation logic that you write yourself. This type of validation allows you to check for values derived at run time.|
You can attach more than one validation control to an input control. For example, you might specify that a control is required, and that it contain a specific range of values.
A related control, the ValidationSummary control, does not perform validation, but it is often used in conjunction with the controls listed above. The purpose of the ValidationSummary control is to display the error messages from all the validation controls on the page together, in a single location. For more information, see Controlling Validation Error Message Display for ASP.NET Server Controls.