Validation Controls

 RequiredFieldValidator

<asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ControlToValidate="txtFirstName" Display="None" ErrorMessage="First Name is required." SetFocusOnError="true" ValidationGroup="Entry"/>

<asp:RequiredFieldValidator ID="rfvJobStatus" runat="server" ControlToValidate="ddlJobStatus" InitialValue="0" Display="None" ErrorMessage="Job Status is required." SetFocusOnError="true" ValidationGroup="Entry"></asp:RequiredFieldValidator>

RangeValidator


Type : Integer,String,Double,Date and Currency
<asp:RangeValidator ID="rngValTxtAge" Type="Integer" MinimumValue="0" MaximumValue="100"
ControlToValidate="txtTest" SetFocusOnError="true" ErrorMessage="Invalid Age" ValidationGroup ="Entry" runat="server"></asp:RangeValidator>

RegularExpressionValidator


<asp:RegularExpressionValidator runat="server" ID="revSSN" ControlToValidate="txtSSN"  Display="None" ValidationExpression="^(\d{9})$" ValidationGroup="Entry"
ErrorMessage="Please enter a SSN number in the format:<br />#########"
SetFocusOnError="true" />

CompareValidator


Type : Integer,String,Double,Date and Currency

<asp:CompareValidator ID="cvDOB" runat="server" ErrorMessage="Invalid Date of Birth"
Operator="DataTypeCheck" Display="None" Type="Date" ControlToValidate="txtDateOfBirth"
ValidationGroup="Entry" />

CustomValidator

Example 1 :
<asp:CustomValidator ID="cvEmplovee" runat="server" ControlToValidate="txtEmployees" Display="None" ClientValidationFunction="CheckInputLen" ErrorMessage="Your Employee length is over 7500 characters."></asp:CustomValidator>

Example 2 :

Pass the ListBox and Validate the SelectionList Using Custom Validator


function ValidateFunction(sender, args) {

var ctl = document.getElementById(sender.controltovalidate);
args.IsValid = ctl.options.length > 0;
}

<asp:CustomValidator runat="server" ID="cusCustom" ControlToValidate="ListBoxID" ValidateEmptyText="true" ValidationGroup="Go" ClientValidationFunction="ValidateFunction"  ErrorMessage="Please Select atleast one" Display="none" />

ValidationSummary


<asp:ValidationSummary ID="ValidationSummay1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="Entry" />

DynamicValidator