Simple ASP.net Validation Control


Below is the code where I have embedded asp.net Validation Controls with our server controls. Just for knowledge I have only given you some quick learning sample how to embed validation controls with our control and how it works.
If you want to know more about ASP.net Validation Controls search for the topic in my previous post. Here I have also disabled the Auto Fill up controls using AutoComplete property off.
<div>
       
        Name : <asp:TextBox ID="txtName" runat="server" AutoComplete="Off" ></asp:TextBox> <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName" ErrorMessage="Please enter Name" Display="None"   SetFocusOnError="true"  ValidationGroup="vgValidate"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="revOnlyChar" runat="server" ControlToValidate="txtName" ErrorMessage="Please enter only character" Display="None"   SetFocusOnError="true"  ValidationExpression="^[a-zA-Z]+$" ValidationGroup="vgValidate"></asp:RegularExpressionValidator>
        Telephone: <asp:TextBox ID="txtTel" runat="server" AutoComplete="Off" ></asp:TextBox> <asp:RequiredFieldValidator ID="rfvTel" runat="server" ControlToValidate="txtTel" ErrorMessage="Please enter Telephone" Display="None"   SetFocusOnError="true"  ValidationGroup="vgValidate"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="revOnlyNum" runat="server" ControlToValidate="txtTel" ErrorMessage="Please enter only Numeric" Display="None" SetFocusOnError="true" ValidationExpression="^\d{10}" ValidationGroup="vgValidate">*</asp:RegularExpressionValidator>
        Age: <asp:TextBox ID="txtAge" runat="server" AutoComplete="Off" ></asp:TextBox> <asp:RequiredFieldValidator ID="rfvAge" runat="server" ControlToValidate="txtAge" ErrorMessage="Please enter Age" Display="None"   SetFocusOnError="true"  ValidationGroup="vgValidate"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="revAge" runat="server" ControlToValidate="txtAge" ErrorMessage="Please enter age above 18 " Display="None" SetFocusOnError="true" ValidationExpression="^\d{2}" ValidationGroup="vgValidate">*</asp:RegularExpressionValidator> <asp:RangeValidator ID="rvAge" runat="server" ControlToValidate="txtAge" Display="None" ErrorMessage="Please enter age range between 18 to 80" MinimumValue="18" MaximumValue="80" ValidationGroup="vgValidate"></asp:RangeValidator>

        <asp:Button ID="btnSave" runat="server" Text="Validate" ValidationGroup="vgValidate" />
        <asp:ValidationSummary ID="vsSave" runat="server" ValidationGroup="vgValidate" ShowMessageBox="true" ShowSummary="false" />
        </div>


Cheers.

Comments