Thursday, 25 October 2012

jquery form validation

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
  <script type="text/javascript">      var _siteRoot = 'index.html', _root = 'index.html';</script>
  <script type="text/javascript" src="js/jquery.js"></script>
  <script type="text/javascript" src="js/scripts.js"></script>

  <script language="javascript" type="text/jscript">
      $(document).ready
  (
  function () {
      $("#<%=btn.ClientID %>").click
  (
  function () {

      if ($("#<%=tb.ClientID %>").val() == "") {
          alert('name should not blank.')
          $("#<%=tb.ClientID %>").focus()
          return false
      }
     else  if ($("#<%=tb1.ClientID %>").val() == "") {
          alert('Address should not blank.')
          $("#<%=tb1.ClientID %>").focus()
          return false
      }
      else if ($("#<%=rb.ClientID %>").is(":checked") == false && $("#<%=rb1.ClientID %>").is(":checked") == false) {
          alert('Please select a gender.')
          return false
      }
      else if ($("#<%=tb2.ClientID %>").val() == "") {
          alert('Email id should not blank.')
          $("#<%=tb2.ClientID %>").focus()
          return false
      }
      else if ($("#<%=cb.ClientID %>").is(":checked") == false && $("#<%=cb1.ClientID %>").is(":checked") == false && $("#<%=cb2.ClientID %>").is(":checked") == false && $("#<%=cb3.ClientID %>").is(":checked") == false) {
          alert('Please select a hobby.')
          return false
      }
      else if ($("#<%=lb.ClientID %> :selected").length  == 0) {
          alert('Please select a interest.')
          $("#<%=lb.ClientID %>").focus()
          return false
      }
      else if ($("#<%=ddl.ClientID %>").get(0).selectedIndex == 0) {
          alert('Please select a interest.')
          $("#<%=ddl.ClientID %>").focus()
          return false
      }
      else if ($("#<%=fu.ClientID %>").val()=="") {
          alert('Please select a phote.')
          return false
      }
  }
  )
  }
  )

  $(document).ready
(
function () {
    $("#<%=fu.ClientID %>").change
(
function () {
    $("#<%=im.ClientID %>").attr("src", $("#<%=fu.ClientID %>").val())
}
)
}
)
$(document).ready
(
function () {
    $("#<%=tb.ClientID %>").keyup
(
function () {
    var m = "~`!#$%^&*()-=+{}[]|:;\\\'\"<>,./?"
    var n = $("#<%=tb.ClientID %>").val()
    for (var i = 0; i < n.length; i++)
        if (m.indexOf(n.charAt(i)) != -1) {
            alert('You can not enter secial charecter.')
            $("#<%=tb.ClientID %>").attr("value", "")
            $("#<%=tb.ClientID %>").focus()
          
        }
}
)
}
)
$(document).ready
(
function () {
    $("#<%=tb2.ClientID %>").blur
(
function () {
    var m = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
    var n = $("#<%=tb2.ClientID %>").val()
    if (n.search(m) == -1) {
        alert('Invalid email id.')
        $("#<%=tb2.ClientID %>").focus()
    }
}
)
}
)
$(document).ready
(
function () {
    $("#<%=tb1.ClientID %>").keyup
(
function () {
    var m = event.keyCode
 
   if(!(m<48 || m>57) || !(m<90 || m>105))
       alert('This is a charecter field.')
 
 
}
)
}
)
$(document).ready
(
function () {
    $("#<%=tb5.ClientID %>").keyup
(
function () {
    var m = event.keyCode
  
  
        var n = "."
        var p = $("#<%=tb5.ClientID %>").val()
        for (var i = 0; i < p.length; i++)
            if (n.indexOf(p.charAt(i)) == 0) {
                var n = $("#<%=tb5.ClientID %>").val().split('.')
                if (n[1].length > 2) {
                    alert('You can not enter more than 2 digits after decimal point')
                    $("#<%=tb5.ClientID %>").attr("value", n[0] + "." + n[1].substring(0, 2))
                    $("#<%=tb5.ClientID %>").focus()

                }
            }

          

        
 
   


}
)
}
)
    $(document).ready
(
function () {
    $("#<%=tb5.ClientID %>").keydown
(
function () {
    var m = event.keyCode
    if (!(m < 65 || m > 90)) {
        alert('This is a integer field.')
        $("#<%=tb5.ClientID %>").focus()
    }
  



}
)
}
)
$(document).ready
(
function () {
    $("#<%=tb6.ClientID %>").keyup
(
function () {
    var m = event.keyCode

  

    if (!(m<65 || m>90)) {
        alert('This is a integer field.')
        $("#<%=tb6.ClientID %>").focus()
    }



}
)
}
)
$(document).ready
    (
    function () {
        $("#<%=tb5.ClientID %>").keypress
    (
    function () {
        var m = event.keyCode
        var n = $("#<%=tb5.ClientID %>").val()

        if (m > 64 && m < 91) {
            var q = ($("#<%=tb5.ClientID %>").val().length - 1)

            var p = $("#<%=tb5.ClientID %>").val().substring(0, q)
            $("#<%=tb5.ClientID %>").attr("value", p)
        }
    }
    )
    }
    )
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="header"><div class="wrap">
   <div id="slide-holder">
<div id="slide-runner">
    <a href=""><img id="slide-img-1" src="images/nature-photo.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-2" src="images/nature-photo1.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-3" src="images/nature-photo2.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-4" src="images/nature-photo3.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-5" src="images/nature-photo4.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-6" src="images/nature-photo4.png" class="slide" alt="" /></a>
    <a href=""><img id="slide-img-7" src="images/nature-photo6.png" class="slide" alt="" /></a>
    <div id="slide-controls">
     <p id="slide-client" class="text"><strong>post: </strong><span></span></p>
     <p id="slide-desc" class="text"></p>
     <p id="slide-nav"></p>
    </div>
</div>
  
    <!--content featured gallery here -->
   </div>
   <script type="text/javascript">
       if (!window.slider) var slider = {}; slider.data = [{ "id": "slide-img-1", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-2", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-3", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-4", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-5", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-6", "client": "siv sankar", "desc": "jay jagannath" }, { "id": "slide-img-7", "client": "siv sankar", "desc": "jay jagannath"}];
   </script>
  </div></div><!--/header-->
  <center>
  <div style="width:993px; height:500px; background-color:White; color:Black; font-family:Verdana">
   <li class="x">&nbsp;</li>
  <li class="y">&nbsp;</li>
  <li class="z"><strong>EMPLOYEE INFORMATION</strong></li>
  <li class="x">Name</li>
  <li class="y">:</li>
  <li class="z"><asp:TextBox ID="tb" runat="server" Width="200"></asp:TextBox></li>
  <li class="x" style="padding-top:10px">Address</li>
  <li class="y" style="padding-top:10px">:</li>
  <li class="z"><asp:TextBox ID="tb1" runat="server" Width="200" Height="30" TextMode="MultiLine"></asp:TextBox></li>
  <li class="x">Gender</li>
  <li class="y">:</li>
  <li class="z"><asp:RadioButton ID="rb" runat="server" Text="Male"  GroupName="a" />&nbsp;<asp:RadioButton ID="rb1" runat="server" Text="Female"  GroupName="a" /></li>
  <li class="x">Email ID</li>
  <li class="y">:</li>
  <li class="z"><asp:TextBox ID="tb2" runat="server" Width="200"></asp:TextBox></li>
   <li class="x" style="padding-top:30px">Hobby</li>
  <li class="y" style="padding-top:30px">:</li>
  <li class="z"><fieldset style="width:198px"><asp:CheckBox ID="cb" runat="server" Text="Reading" /><br /><asp:CheckBox ID="cb1" runat="server" Text="Writing" /><br /><asp:CheckBox ID="cb2" runat="server" Text="Singing" /><br /><asp:CheckBox ID="cb3" runat="server" Text="Playing" /></fieldset></li>
  <li class="x"  style="padding-top:20px">Interest</li>
  <li class="y"  style="padding-top:20px">:</li>
  <li class="z"><asp:ListBox ID="lb" runat="server" Rows="3" Width="200">
  <asp:ListItem Text="Cricket"></asp:ListItem>
  <asp:ListItem Text="Hockey"></asp:ListItem>
  <asp:ListItem Text="Football"></asp:ListItem>
  <asp:ListItem Text="Baseball"></asp:ListItem>
  </asp:ListBox></li>
  <li class="x">Salary</li>
  <li class="y">:</li>
  <li class="z"><asp:TextBox ID="tb5"   runat="server" Width="150"></asp:TextBox></li>
  <li class="x">Question</li>
  <li class="y">:</li>
  <li class="z"><asp:DropDownList Width="200" ID="ddl" runat="server">
  <asp:ListItem Text="--------Select--------"></asp:ListItem>
  <asp:ListItem Text="What is ur name?"></asp:ListItem>
  <asp:ListItem Text="What is ur favority place?"></asp:ListItem>
  <asp:ListItem Text="What is ur favority song?"></asp:ListItem>
  <asp:ListItem Text="What is ur favority movie?"></asp:ListItem>
  </asp:DropDownList></li>
   <li class="x">Age</li>
  <li class="y">:</li>
  <li class="z"><asp:TextBox ID="tb6" runat="server" Width="100"></asp:TextBox></li>
  <li class="x" style="padding-top:40px">Phote</li>
  <li class="y" style="padding-top:40px">:</li>
  <li class="z" style=" width:165px"><asp:Image ID="im" runat="server" Height="100" Width="100" /></li>
  <li class="z" style=" width:365px; padding-top:40px "><asp:FileUpload ID="fu"  runat="server" /></li>
  <li class="x">&nbsp;</li>
  <li class="y">&nbsp;</li>
  <li class="z"><asp:Button ID="btn" runat="server" Text="Submit" Width="80" />&nbsp;<asp:Button ID="Button1" runat="server" Text="Reset" Width="80" /></li>
    
  </div>
  </center>
    </div>
    </form>
</body>
</html>


No comments:

Post a Comment