this is my javascript code and i am not understanding the mistake in this,please help me?

Ads
 

this is my javascript code and i am not understanding the mistake in this,please help me?

<html>
    <h2>Form Validation</h2>
        <script language = "Javascript">
          function checkEmail() {
            if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
            return true;
            }
            return false; 
          }
          function checkName(str){
              var re = /[^a-zA-Z]/g
              if (re.test(str)) return false;
              return true;
            }
            function checkAddress(str){
              var re = /[^[a-z][A-Z][0-9]]/g
              if(re.test(str)) return false;
              return true;
            }
            function checkMobile(str){
                var re=/^([7-9]{1})([0-9]{9})$/g
        if(re.test(str)) return false;
        return true;
        }
          function validate(){
            var emailID=document.form.email;
            var nn1=document.form.fname;
            var nn2=document.form.lname;
            var addr1=document.form.add1;
            var addr2=document.form.add2;
            var addr3=document.form.add3;
            var gen=document.form.gender;
            var mobile=document.form.mobilenumber;
            var city=document.form.cityname;
            var state=document.form.statename;
            var zip=document.form.zip1;
            if((nn1.value==null)||(nn1.value=="")){
            alert("Please Enter your First Name!")
            nn1.focus();
            return false
            }
            if((nn2.value==null)||(nn2.value=="")){
            alert("Please Enter your Last Name!")
            nn2.focus();
            return false
            }
            if(checkName(nn1.value)==false){
            nn1.value=""
            alert("Invalid Name!");
            nn1.focus()
            return false
            }
            if(checkName(nn2.value)==false){
            nn2.value=""
            alert("Invalid Name!");
            nn2.focus()
            return false
            }
            if ( ( gen[0].checked == false ) && ( gen[1].checked == false ) ){
                alert("please check your gender");
                gen.focus();
                return false;
            }
            if((emailID.value==null)||(emailID.value=="")){
            alert("Please Enter your Email ID!")
            emailID.focus();
            return false;
            }
            if (checkEmail(emailID.value)==false){
            emailID.value=""
            alert("Invalid Email Adderess!");
            emailID.focus()
            return false
            }
            if(checkMobile(mobile.value==null)||mobile.value==""){
                alert("please Enter Valid Mobile number")
                mobile.focus();
                return false; 
           }
            if ((addr1.value==null)||(addr1.value=="")){
            alert("Please Enter your Address!")
            addr1.focus()
            return false
            }
            if (checkAddress(addr1.value)==false){
            addr1.value=""
            alert("Invalid Adderess!");
            addr1.focus()
            return false
            }
            if ((add2.value==null)||(add2.value=="")){
            alert("Please Enter your Address!")
            add2.focus()
            return false
            }
            if (checkAddress(addr2.value)==false){
            addr2.value=""
            alert("Invalid Adderess!");
            addr2.focus()
            return false
            }
            if ((addr3.value==null)||(addr3.value=="")){
            alert("Please Enter your Address!")
            addr3.focus()
            return false
            }
            if (checkAddress(addr3.value)==false){
            addr3.value=""
            alert("Invalid Adderess!");
            addr3.focus()
            return false
            }
            if((city.value==null)||(nn2.value=="")){
            alert("Please Enter your city!")
            city.focus();
            return false
            }
            if(checkName(city.value)==false){
            city.value=""
            alert("Invalid Name!");
            city.focus()
            return false
            }
            if((state.value==null)||(state.value=="")){
            alert("Please Enter your city Name!")
            state.focus();
            return false
            }
            if(checkName(state.value)==false){
            state.value=""
            alert("Invalid Name!");
            state.focus()
            return false
            }
             if( zip.value == "" || isNaN(zip.value ) ||zip.value.length != 6 ){
             alert( "Please provide a zip in the format ######." );
             zip.focus() ;
             return false;
             }
            {
            return true
          }
        </script>
        <form name="form" method="post" onSubmit="return validate()">
        <pre>
        First Name:              <input type="text" name="fname" size="30"><br>
        Last Name:               <input type="text" name="lname" size="30"><br>
        Gender: <input type="radio" name="gender" value="Male"> Male
                <input type="radio" name="gender" value="Female"> Female
                <br>
        Enter an Email Address : <input type="text" name="email" size="30"><br>
        Mobile Number:<input type="text" name="mobilenumber" size="10"><br>
        Address1:<input type="text" name="add1"><br>
        Address2:<input type="text" name="add2"><br>
        Address3:<input type="text" name="add3"><br>
        City  :<input type="text" name="cityname"><br>
        State:<input type="text" name="statename"><br>
        ZIP:<input type="text" name="zip1"><br>
        <input type="submit" name="Submit" value="Submit">
        </pre>
        </form>
</html>
View Answers

October 31, 2012 at 3:53 PM

Here is your required code, we have modified it.

<html>
    <h2>Form Validation</h2>
        <script language = "Javascript">
          function checkEmail() {
            if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
            return true;
            }
            return false; 
          }
          function checkName(str){
              var re = /[^a-zA-Z]/g
              if (re.test(str)) return false;
              return true;
            }
            function checkAddress(str){
              var re = /[^[a-z][A-Z][0-9]]/g
              if(re.test(str)) return false;
              return true;
            }
            function checkMobile(str){
                var re=/^([7-9]{1})([0-9]{9})$/g
        if(re.test(str)) return false;
        return true;
        }
          function validate(){
            var emailID=document.form.email;
            var nn1=document.form.fname;
            var nn2=document.form.lname;
            var addr1=document.form.add1;
            var addr2=document.form.add2;
            var addr3=document.form.add3;
            //var gen=document.form.gender;
            var mobile=document.form.mobilenumber;
            var city=document.form.cityname;
            var state=document.form.statename;
            var zip=document.form.zip1;
            if((nn1.value==null)||(nn1.value=="")){
            alert("Please Enter your First Name!")
            nn1.focus();
            return false
            }
            if(checkName(nn1.value)==false){
            nn1.value=""
            alert("Invalid Name!");
            nn1.focus()
            return false
            }
            if((nn2.value==null)||(nn2.value=="")){
            alert("Please Enter your Last Name!")
            nn2.focus();
            return false
            }
            if(checkName(nn2.value)==false){
            nn2.value=""
            alert("Invalid Name!");
            nn2.focus()
            return false
            }
            if((document.form.gender[0].checked==false )&&(document.form.gender[1].checked==false )){
                alert("please check your gender");
                document.form.gender[0].focus();
                return false;
            }
            if((emailID.value==null)||(emailID.value=="")){
            alert("Please Enter your Email ID!")
            emailID.focus();
            return false;
            }
            if(checkEmail(emailID.value)==false){
            emailID.value=""
            alert("Invalid Email Address!");
            emailID.focus()
            return false
            }

October 31, 2012 at 3:53 PM

Here is your required code, we have modified it.

<html>
    <h2>Form Validation</h2>
        <script language = "Javascript">
          function checkEmail() {
            if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
            return true;
            }
            return false; 
          }
          function checkName(str){
              var re = /[^a-zA-Z]/g
              if (re.test(str)) return false;
              return true;
            }
            function checkAddress(str){
              var re = /[^[a-z][A-Z][0-9]]/g
              if(re.test(str)) return false;
              return true;
            }
            function checkMobile(str){
                var re=/^([7-9]{1})([0-9]{9})$/g
        if(re.test(str)) return false;
        return true;
        }
          function validate(){
            var emailID=document.form.email;
            var nn1=document.form.fname;
            var nn2=document.form.lname;
            var addr1=document.form.add1;
            var addr2=document.form.add2;
            var addr3=document.form.add3;
            //var gen=document.form.gender;
            var mobile=document.form.mobilenumber;
            var city=document.form.cityname;
            var state=document.form.statename;
            var zip=document.form.zip1;
            if((nn1.value==null)||(nn1.value=="")){
            alert("Please Enter your First Name!")
            nn1.focus();
            return false
            }
            if(checkName(nn1.value)==false){
            nn1.value=""
            alert("Invalid Name!");
            nn1.focus()
            return false
            }
            if((nn2.value==null)||(nn2.value=="")){
            alert("Please Enter your Last Name!")
            nn2.focus();
            return false
            }
            if(checkName(nn2.value)==false){
            nn2.value=""
            alert("Invalid Name!");
            nn2.focus()
            return false
            }
            if((document.form.gender[0].checked==false )&&(document.form.gender[1].checked==false )){
                alert("please check your gender");
                document.form.gender[0].focus();
                return false;
            }
            if((emailID.value==null)||(emailID.value=="")){
            alert("Please Enter your Email ID!")
            emailID.focus();
            return false;
            }
            if(checkEmail(emailID.value)==false){
            emailID.value=""
            alert("Invalid Email Address!");
            emailID.focus()
            return false
            }

October 31, 2012 at 3:54 PM

continue..

if(checkMobile(mobile.value==null)||mobile.value==""){
                    alert("please Enter Valid Mobile number")
                    mobile.focus();
                    return false; 
                }
                if ((addr1.value==null)||(addr1.value=="")){
                alert("Please Enter your Address!")
                addr1.focus()
                return false
                }
                if (checkAddress(addr1.value)==false){
                addr1.value=""
                alert("Invalid Adderess!");
                addr1.focus()
                return false
                }
                if ((add2.value==null)||(add2.value=="")){
                alert("Please Enter your Address!")
                add2.focus()
                return false
                }
                if (checkAddress(addr2.value)==false){
                addr2.value=""
                alert("Invalid Adderess!");
                addr2.focus()
                return false
                }
                if ((addr3.value==null)||(addr3.value=="")){
                alert("Please Enter your Address!")
                addr3.focus()
                return false
                }
                if (checkAddress(addr3.value)==false){
                addr3.value=""
                alert("Invalid Adderess!");
                addr3.focus()
                return false
                }
                if((city.value==null)||(nn2.value=="")){
                alert("Please Enter your city!")
                city.focus();
                return false
                }
                if(checkName(city.value)==false){
                city.value=""
                alert("Invalid Name!");
                city.focus()
                return false
                }
                if((state.value==null)||(state.value=="")){
                alert("Please Enter your city Name!")
                state.focus();
                return false
                }
                if(checkName(state.value)==false){
                state.value=""
                alert("Invalid Name!");
                state.focus()
                return false
                }
                 if( zip.value == "" || isNaN(zip.value ) ||zip.value.length != 6 ){
                 alert( "Please provide a zip in the format ######." );
                 zip.focus() ;
                 return false;
                 }

                return true
              }
            </script>
            <form name="form" method="post" onSubmit="return validate();">
            <pre>
            First Name:              <input type="text" name="fname" size="30"><br>
            Last Name:               <input type="text" name="lname" size="30"><br>
            Gender: <input type="radio" name="gender" value="Male"> Male
                    <input type="radio" name="gender" value="Female"> Female
                    <br>
            Enter an Email Address : <input type="text" name="email" size="30"><br>
            Mobile Number:<input type="text" name="mobilenumber" size="10"><br>
            Address1:<input type="text" name="add1"><br>
            Address2:<input type="text" name="add2"><br>
            Address3:<input type="text" name="add3"><br>
            City  :<input type="text" name="cityname"><br>
            State:<input type="text" name="statename"><br>
            ZIP:<input type="text" name="zip1"><br>
            <input type="submit" name="Submit" value="Submit">
            </pre>
            </form>
    </html>

Ads









Related Tutorials/Questions & Answers:
this is my javascript code and i am not understanding the mistake in this,please help me?
I need help on my Java code.... please please help me out!?
Advertisements
Begineer Help Help Please Thanks A million ) I am using Jcreator
I am having problem with configuring Hibernate sessionfactory. Please Help
i am unable to identify the error in my code
i am unable to identify the error in my code
Not sure whats wrong with my code HELP PLEASE?!?!
Please help me to modify my java code from php code
Please help me to modify my java code from php code
PLEASE HELP WITH MY JAVA
please help me solve this problem when i am create database connection using servlecontext
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
this is my file upload page, here i am not getting tags input field value to my servlet,please suggest a solution?
Please Help To Solve My Problem
i need a help in this please
Please help with this code
i need some help in understanding the following codes.thanks..
Please Provide the direct Downloadable source code for better understanding
please help.. this my importtant project..!!!!!
how do i update my database with the help of update syntax in html <text/javascript>? How to write 'where' statement in this?
ajax code please help to solve this........
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
could anyone please help with the code.
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
My screen EPAD is broken ...please help
Help me please with my final homework
I am trying to create domains for column attributes of my data dictionary?
can i know the error in this code... am unable to run this code
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....
how to i convert this case to loop...please help.....

Ads