Validation Controls in Web Page

Validation Controls in Web Page is used to validate the user input at client side as well as server side

Validation Controls in Web Page

 Validation controls are added to a Web Forms page like other server controls. You can attach more than one validation control to an input control.

There are following Validation controls in ASP.Net

The CompareValidator server control compares the values of two controls. CompareValidator uses three key properties to perform its validation. ControlToValidate and ControlToCompare contain the values to compare. Operator defines the type of comparison to perform--for example, Equal or Not Equal.

The RangeValidator server control tests whether an input value falls within a given range. RangeValidator uses three key properties to perform its validation. ControlToValidate contains the value to validate. MinimumValue and MaximumValue define the minimum and maximum values of the valid range.

The RegularExpressionValidator server control checks that the entry 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.

The RequiredFieldValidator server control checks for blank data. All the mandatory fields in web form must be validated by this validator.


<%@ Page Language="C#" %>

  <title>Form Validation Sample</title>
      <font face="Verdana">Sign In Form Validation Sample</font></h3>
    <form action="validationform_cs.aspx" method="post" runat="server">
      <hr width="600" size="1" noshade>
        <asp:ValidationSummary ID="valSum" runat="server" HeaderText="You must enter a valid value in the following fields:"
          DisplayMode="SingleParagraph" Font-Names="verdana" Font-Size="12" />
        <br />
        <br />
        <!-- sign-in -->
        <table border="0" width="600">
            <td align="right">
              <font face="Arial" size="2">Email Address:</font>
              <asp:TextBox ID="email" Width="200px" MaxLength="60" runat="server" />
              <asp:RequiredFieldValidator ID="emailReqVal" ControlToValidate="email" ErrorMessage="Email. "
                Display="Dynamic" Font-Names="Verdana" Font-Size="12" runat="server">
              <asp:RegularExpressionValidator ID="emailRegexVal" ControlToValidate="email" ErrorMessage="Email. "
                Display="Static" ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
                Font-Names="Arial" Font-Size="11" runat="server">
            Not a valid e-mail address.  Must follow
        <br />
        <br />
        <input runat="server" type="submit" value="Sign In" />
        <br />
        <br />
        <hr width="600" size="1" noshade="noshade" />



By Pritam Baldota   Popularity  (2749 Views)