Monday, May 9, 2016

Validation controls in ASP.Net

In ASP.Net validation controls are used to check the information that the user enter is valid or not. There are six types of validation control are given below:
  1. RequiredFieldValidation Control
  2. CompareValidator Control
  3. RangeValidator Control
  4. RegularExpressionValidator Control
  5. CustomValidator Control
  6. ValidationSummary
RequiredFieldValidation Control

The RequiredFieldvalidation control is used to see the data is entered for the input control, In other words we use RequiredFieldvalidation control for mandatory field.


<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" Style="top: 100px;

        left: 300px; position: absolute; height: 30px; width: 130px" ErrorMessage="password required"
        ControlToValidate="TextBox2"></asp:RequiredFieldValidator>

CompareValidator Control

CompareValidator Control is used to compare the data is input in one input control with another input control. It is used to compare the password from one textbox to another textbox at a time of registration.


<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" Style="top: 100px;
        left: 300px; position: absolute; height: 30px; width: 130px" ErrorMessage="password required"
        ControlToValidate="TextBox3"></asp:RequiredFieldValidator>
   
RangeValidator Control


RangeValidator Control is used to check the value of the input control that is in valid range, for example minimum and maximum value of the input control.

<asp:RangeValidator ID="RangeValidator1" runat="server" Style="top: 150px; left: 300px;
            position: absolute; height: 20px; width: 90px"
        ErrorMessage="RangeValidator" ControlToValidate="TextBox4" MaximumValue="50"
        MinimumValue="20" Type="Integer"></asp:RangeValidator>
 
 RegularExpressionValidator Control

RegularExpressionValidator Control is used to check user’s input based on a pattern that you define by using a regular expression, it is used to check the valid phone number, email address, zip code etc.
 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Style="top: 200px; left: 300px; position: absolute; height: 20px; width: 160px"        ErrorMessage="RegularExpressionValidator"ControlToValidate="TextBox5"        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
 
CustomValidator Control
  
CustomValidator Control is used to allow write a method to handle the validation of the entered value.

Validation Summery

Validation summery is used to display report of all validations error occurred in the web page.

No comments:

Post a Comment