|
|
Answer: A validator is a computer program used to check the validity or syntactical correctness of a fragment of code or text. IN ASP.NET there are six different types of Validators. 1.Required Field Validator. RequiredFieldValidator:-Ensure that the control has a value to assign in it or user does not skip an entry. For Example:- <asp:Textbox id="txtMobileNumber" runat="server"></asp:Textbox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="txtMobileNumber" ErrorMessage="Mobile Number is a required field." ForeColor="Red"> </asp:RequiredFieldValidator>
Regular ExpressionValidator:-Ensure that the value of the control matches the expression of validator that is specified. This type of validation enables you to check for sequence of character, such as e-mail address, telephone number, postal code and so on. For Example:- <asp:TextBox ID="txtE-Mail" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtPassword" ErrorMessage="Please Enter a Valid E-Mail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> // for internet E-Mail. </asp:RegularExpressionValidator>
For Example:- <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox> <asp:TextBox ID="txtConfirmPassword" runat="server"></asp:TextBox> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPassword" ControlToValidate="txtConfirmPassword" ErrorMessage="Password does not match"> </asp:CompareValidator>
For Example:- <asp:TextBox ID="txtAmount" runat="server"></asp:TextBox> <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtPassword" ErrorMessage="RangeValidator" MaximumValue="5000" MinimumValue="100"> </asp:RangeValidator>>
ValidationSummary:-This validator is used to
displays a detailed summary on the validation errors that currently exist. |