Validation ASP.Net Tutorial

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="Validators" %>



    Untitled Page

  function EmpIDClientValidate(ctl, args)
  {
    args.IsValid=(args.Value%5 == 0);
  }



    
  Name:
                                     ID="ValidateName" 
                                ControlToValidate="Name" 
                                ErrorMessage="Name is required"
                              Display="dynamic">*
    
                                        ID="ValidateName2" 
                                    ControlToValidate="Name" 
                                    validationExpression="[a-z A-Z]*"
                                  ErrorMessage="Name cannot contain digits" 
                                  Display="dynamic">*
      
    ID (multiple of 5):
        
                                    ID="ValidateEmpID" 
                                ControlToValidate="EmpID" 
                                ErrorMessage="ID is required"
                                    Display="dynamic">*
    
                             ID="ValidateEmpID2" 
                         ControlToValidate="EmpID" 
                         ClientValidationFunction="EmpIDClientValidate"
                             ErrorMessage="ID must be a multiple of 5" 
                             Display="dynamic" 
                             OnServerValidate="ValidateEmpID2_ServerValidate">*
      
    Day off:08/08/08-08/20/08
    
                                    ID="ValidateDayOff" 
                                ControlToValidate="DayOff" 
                                ErrorMessage="Day Off is required"
                                    Display="dynamic">*
    
                            ID="ValidateDayOff2" 
                        ControlToValidate="DayOff" 
                        MinimumValue="08/08/2008"
                      MaximumValue="08/20/2008" 
                      Type="Date" 
                      ErrorMessage="Day Off is not within the valid interval" 
                      Display="dynamic" 
                      SetFocusOnError="True">*
    
    Age ( >= 18 ):
    
                                    ControlToValidate="Age" 
                                ErrorMessage="Age is required" 
                                Display="dynamic"
                              ID="Requiredfieldvalidator1" 
                              Name="Requiredfieldvalidator1">*
    
                              ID="ValidateAge" 
                          ControlToValidate="Age" 
                          ValueToCompare="18" 
                          Type="Integer"
                        Operator="GreaterThanEqual" 
                        ErrorMessage="You must be at least 18-year-old" 
                        Display="dynamic">*
      
    E-mail:
    
                                    ControlToValidate="Email" 
                                ErrorMessage="E-mail is required" 
                                Display="dynamic"
                              ID="Requiredfieldvalidator2" 
                              Name="Requiredfieldvalidator2">*
    
                                        ID="ValidateEmail" 
                                    ControlToValidate="Email" 
                                    validationExpression=".*@.{2,}\..{2,}"
                                  ErrorMessage="E-mail is not in a valid format" Display="dynamic">*
      
    Password:
    
                                    ControlToValidate="Password" 
                                ErrorMessage="Password is required"
                                    Display="dynamic" 
                                    ID="Requiredfieldvalidator3" 
                                    Name="Requiredfieldvalidator3">
    
    
    Re-enter Password:
    
                                    ControlToValidate="Password2" 
                                ErrorMessage="Password2 is required"
                              Display="dynamic" 
                              ID="Requiredfieldvalidator4" 
                              Name="Requiredfieldvalidator4">
    
    
                              ControlToValidate="Password2" 
                          ControlToCompare="Password" 
                          Type="String"
                ErrorMessage="The passwords don't match" 
                Display="dynamic" 
                ID="Comparevalidator1" 
                Name="Comparevalidator1">
      
    
    

    
    
    
    
    Please review the following errors:"
        ShowSummary="true" />
    
    

    


File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Validators : System.Web.UI.Page
{
  protected void Submit_Click(object sender, EventArgs e)
  {
    if (Page.IsValid)
      Result.Text = "Thanks for sending your data";
    else
      Result.Text = "There are some errors, please correct them and re-send the form.";
  }
  protected void OptionsChanged(object sender, EventArgs e)
  {
    foreach (BaseValidator valCtl in Page.Validators)
    {
      valCtl.Enabled = EnableValidators.Checked;
      valCtl.EnableClientScript = EnableClientSide.Checked;
    }
    ValidationSum.ShowMessageBox = ShowMsgBox.Checked;
    ValidationSum.ShowSummary = ShowSummary.Checked;
  }
  protected void ValidateEmpID2_ServerValidate(object source, ServerValidateEventArgs args)
  {
    try
    {
      args.IsValid = (int.Parse(args.Value) % 5 == 0);
    }
    catch
    {
      args.IsValid = false;
    }
  }
}