Validation Controls in ASP.NET: System.Web.UI.WebControls Class

System.Web.UI.WebControls contains all the validation controls. Here is a brief description of all the validation controls in ASP.NET:

1. RequiredFieldValidator ()

Checks that the validated control contains a value. It cannot be empty.

id="validateTxtName"
runat="server"
display="static"
controlToValidate="txtName"
errorMessage="Name must be entered" >

2. RegularExpressionValidator ()

Checks the value against a regular expression (pattern). Checks that the value in the control matches a specified regular expression. If the validated control is empty, no validation takes place. The most important property in the RegularExpressionValidator is ValidationExpression.

id="regvH"
runat="server"
display="static"
controlToValidate="txtH"
errorMessage="Hours must be 1-3 digits only"
validationExpression="\d{1,3}">

3. CompareValidator ()

Checks if the value is acceptable compared to a given value or compared to the content of another control. In other words, it checks that the value in the validated control matches the value in another control or a specific value. The data type and comparison operation can be specified. If the validated control is empty, no validation takes place. The most important properties in the CompareValidator are ControlToCompare, Operator, and type.

id="comvR"
runat="server"
display="static"
controlToValidate="txtR"
errorMessage="Rate must be numeric"
ValueToCompare="txtA">

4. RangeValidator (

Checks if the input control’s value is within a specified range. In other words, it checks that the value in the validated control is within the specified text or numeric range. If the validated control is empty, no validation takes place. The most important properties in the RangeValidator are MaximumValue, MinimumValue, and type.

id="ranvDependents"
runat="server"
display="static"
controlToValidate="txtDependents"
errorMessage="Must be from 0 to 10"
type="Integer"
minimumValue=0
maximumValue=10>

5. CustomValidator ()

Allows you to develop custom validation. Performs user-defined validation on an input control using a specified function (client-side, server-side, or both). If the validated control is empty, no validation takes place. The most important property in the CustomValidator is ClientValidationFunction.

id="cusvDeptNum"
runat="server"
display="static"
controlToValidate="txtDeptNum"
onServerValidate="validateDeptNum"
errorMessage="Must be in multiples of 10" >

6. ValidationSummary ()

Displays a summary of all current validation errors. In other words, reports a summary of all errors. The most important properties in the ValidationSummary are DisplayMode, ShowHeaderText, ShowMessageBox, and ShowSummary.

id="valSummary"
runat="server"
display="static"
headerText="Please correct the following errors"
showSummary= "True" />