Click here to Skip to main content
16,017,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello every one,
I am validating a sign up page in userprofile.aspx page.I have implemented javascript code as well.But i am not able to validate aspx page using java script validation.Please any one do help me.
My code is below.

JavaScript
<head>
   
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
        $(document).ready(function () {

            $("#panel").slideToggle("fast");

        });
    </script>
  
    <script type="text/javascript">
        function validate() {
            var email = document.signup.email.value;
            if (email == '') {
                document.getElementById("error8").innerHTML = "<font color="red">Please Enter Email Id </font>";
                document.signup.email.focus();
                return false;
            }
            var ck_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (!ck_email.test(email)) {
                document.getElementById("error8").innerHTML = "<font color="red">Please Enter Correct Email Id </font>";
                document.signup.email.focus();
                return false;
            } else {
                document.getElementById("error8").innerHTML = "";
            }
            var nam = document.signup.username.value;
            if (nam == '') {
                document.getElementById("error9").innerHTML = "<font color="red">Please Enter Your Name </font>";
                document.signup.username.focus();
                return false;
            }
            var ck_nam = /^[a-zA-Z ]{2,30}$/;
            if (!ck_nam.test(nam)) {
                document.getElementById("error9").innerHTML = "<font color="red">Please Enter Correct  Name</font>";
                document.signup.username.focus();
                return false;
            } else {
                document.getElementById("error9").innerHTML = "";
            }

            var pass = document.signup.password.value;
            if (pass == '') {
                document.getElementById("error").innerHTML = "<font color="red">Please Enter Password</font>";
                document.signup.password.focus();
                return false;
            }
            if (pass.length < 6 || pass.length > 12) {
                document.getElementById("error").innerHTML = "<font color="red">Your Password Must Be 6 to 12 Characters</font>";
                document.signup.password.focus();
                return false;
            } else {
                document.getElementById("error").innerHTML = "";
            }
            var pas = document.signup.password1.value;
            if (pas == '') {
                document.getElementById("err").innerHTML = "<font color="red">Please Enter Password</font>";
                document.signup.password1.focus();
                return false;
            }
            if (pass != pas) {
                document.getElementById("err").innerHTML = "<font color="red"> Password Doesnot Match</font>";
                document.signup.password1.focus();
                return false;
            } else {
                document.getElementById("err").innerHTML = "";
            }
        }
		
    </script>
 
</head>
<body>
    
                            <a href="login.html" class="btn btn-danger btn-inverse btn-navbar">Login</a> <span><a>
                                href="signup.html" class="btn btn-success btn-navbar">Sign Up</a></span>
                        <form method="post" action="" class="form-horizontal" id="signup" name="signup"  runat="server">
                        <div align="center">
                            <span id="error8"></span>
                        </div>
                       
                                <div class="left-inner-addon">
                                    <div align="center">
                                        class="icon-envelope" id="email" align="center">
                                        <asp:TextBox ID="username" runat="server">
                                     <%--   <input type="text"  id="username" placeholder="Username" />--%>
                                        </div>
                                </div>
                            </label>
                        
                        <div align="center">
                            <span id="error"></span>
                        </div>
                        <div class="control-group">
                            <label for="password">
                                <div class="left-inner-addon">
                                    <div align="center">
                                        ^__i class="icon-lock">
                                        <asp:TextBox ID="password" runat="server">
                                        <%--<input type="password" name="password" id="password" placeholder="Password" />--%>
                                    </div>
                                </div>
                            </label>
                        </div>
                        <div align="center">
                            <span id="err"></span>
                        </div>
                      
                                <div class="left-inner-addon">
                                    <div align="center">
                                        ^__i class="icon-lock">
                                        <asp:TextBox ID="password1" runat="server">
                                        <%--<input type="password" name="password1" id="password1" placeholder="Confirm Password" />--%>
                                    </div>
                                </div>
                            </label>
                        
                        <br />
                        <div class="control-group">
                            <div align="center">
                            <asp:button ID="signup1" runat="server" text="Button"  class="btn btn-success btn-large" OnClientClick="return validate()"/>
                               <%-- <input type="submit" class="btn btn-success btn-large" name="signup" value="Create account"
                                     önclick="return validate()">--%>
                                    </div>
                        </div>
                        </label>
                        </form>
Posted
Updated 29-Dec-13 19:43pm
v2
Comments
Gitanjali Singh 30-Dec-13 1:44am    
Put debugger and check.
Anurag Sinha V 30-Dec-13 1:44am    
How are you calling the Validate function???
Anurag Sinha V 30-Dec-13 1:54am    
IMO, your code var email = document.signup.email.value and variables equivalent to it are not picking up correct values..why don't u use var email=document.getElementById('<%=email.ClientID%>'); and try....

1 solution

Hi...

you can try this code

XML
<script language="javascript" type="text/javascript">
        
       function validatelogin() {

            if (document.getElementById("<%=txtusername.ClientID%>").value == "") {
                alert("UserName Feild can not be blank");
                document.getElementById("<%=txtusername.ClientID%>").focus();
                return false;
            }
            if (document.getElementById("<%=txtpassword.ClientID%>").value == "") {
                alert("Password Feild can not be blank");
                document.getElementById("<%=txtpassword.ClientID%>").focus();
                return false;
            }


        }


in button click

XML
<asp:ImageButton ID="imglogin" runat="server" ImageUrl="~/Images/login1.png" OnClick="imglogin_Click"
                       OnClientClick="return validatelogin()" /></div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900