Freigeben über


Types of Validation for ASP.NET Server Controls

The following table lists ASP.NET validation controls and how you can use them.

Security noteSecurity Note:

By default, ASP.NET Web pages automatically validate that malicious users are not attempting to send script to your application. For more information, see Script Exploits Overview.

Type of validation

Control to use

Description

Required entry

RequiredFieldValidator

Ensures that the user does not skip an entry. For details, see How to: Validate Required Entries for ASP.NET Server Controls.

Comparison to a value

CompareValidator

Compares a user's entry against a constant value, against the value of another control (using a comparison operator such as less than, equal, or greater than), or for a specific data type. For details, see How to: Validate Against a Specific Value for ASP.NET Server Controls and How to: Validate Against a Data Type for ASP.NET Server Controls.

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. For details, see How to: Validate Against a Range of Values for ASP.NET Server Controls.

Pattern matching

RegularExpressionValidator

Checks that the entry matches a pattern defined by a regular expression. This type of validation enables you to check for predictable sequences of characters, such as those in e-mail addresses, telephone numbers, postal codes, and so on. For details, see How to: Validate Against Patterns for ASP.NET Server Controls.

User-defined

CustomValidator

Checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time. For details, see How to: Validate with a Custom Function for ASP.NET Server Controls and How to: Validate Against Values in a Database for ASP.NET Server Controls.

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 also contains a specific range of values.

A related control, the ValidationSummary control, does not perform validation, but is often used in conjunction with other validation controls to display the error messages from all the validation controls on the page together. For more information, see How to: Control Validation Error Message Display for ASP.NET Server Controls.

See Also

Other Resources

Validation ASP.NET Controls