Search This Blog

10 November 2009

Validation Control

ASP.NET have 5 types of validation feature, they are Required-FieldValidator, RangeValidator, RegularExpressionValidator CompareValidator and CustomValidator which have different function each other. The five validation control can be found in validation group control in the toolbox menu of Visual Web Developer 2008 Express Edition.

The fisrt step should be done by web developer before using all validation control is to change CausesValidation property value to be true in all text box in the web form.

1. RequiredFieldValidator

Use the RequiredFieldValidator control to make an input control a mandatory field. The input control fails validation if the value it contains does not change from its initial value when validation is performed. This prevents the user from leaving the associated input control unchanged. By default, the initial value is an empty string (""), which indicates that a value must be entered in the input control for it to pass validation

2. RangeValidator

The RangeValidator control allows you to check whether a user's entry is between a specified upper and a specified lower boundary. You can check ranges within pairs of numbers, alphabetic characters, and dates. Boundaries are expressed as constants. Use the ControlToValidate property to specify the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range, respectively. The Type property is used to specify the data type of the values to compare. The values to compare are converted to this data type before any comparison is performed

3. RegularExpressionValidator

The RegularExpressionValidator control is used to determine whether the value of an input control 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.

4. CompareValidator

The CompareValidator control allows you to compare the value entered by the user into an input control, such as a TextBox control, with the value entered into another input control, or with a constant value. You can also use the CompareValidator control to determine whether the value entered into an input control can be converted to the data type specified by the Type property

5. CustomValidator

The CustomValidator control allows you to create a validation control with customized validation logic. For example, you can create a validation control that checks whether the value entered into a text box is an even number.