Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Srikanth
Validations
2 Answer(s)      a year and 6 months ago
Posted in : Development process


Javascript validation is working fine in Internet Explorer browser but it is not working in Mozilla. Can you please let me know the reason.


Advertisement
View Answers

October 3, 2012 at 3:49 PM


Here is an example that validates some fields of html form.

<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 validate(){
            var emailID=document.form.email;
              var nn=document.form.name;
                var add=document.form.address;

            if((nn.value==null)||(nn.value=="")){
            alert("Please Enter your Name!")
            nn.focus();
            return false
            }
            if(checkName(nn.value)==false){
            nn.value=""
            alert("Invalid Name!");
            nn.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 ((add.value==null)||(add.value=="")){
            alert("Please Enter your Address!")
            add.focus()
            return false
            }
            if (checkAddress(add.value)==false){
            add.value=""
            alert("Invalid Adderess!");
            add.focus()
            return false
            }
            if(document.form.qua.selectedIndex==""){
            alert ( "Please select your qualification!" );
     return false;  
    }
            return true
          }
        </script>
        <form name="form" method="post" onSubmit="return validate()">
        <pre>
        Enter Name:              <input type="text" name="name" size="30"><br>
        Enter an Email Address : <input type="text" name="email" size="30"><br>
        Enter Address            <textarea name="address" rows="5" cols="23"></textarea><br>
        Select Qualification:    <select name="qua">
                                 <option value="BTech">BTech</option>
                                 <option value="MBBS">MBBS</option>
                                 <option value="MBA">MBA</option>
                                 <option value="MCA">MCA</option>
                                 </select><br>

        <input type="submit" name="Submit" value="Submit">
        </pre>
        </form>
</html>


October 3, 2012 at 3:49 PM


Here is an example that validates some fields of html form.

<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 validate(){
            var emailID=document.form.email;
              var nn=document.form.name;
                var add=document.form.address;

            if((nn.value==null)||(nn.value=="")){
            alert("Please Enter your Name!")
            nn.focus();
            return false
            }
            if(checkName(nn.value)==false){
            nn.value=""
            alert("Invalid Name!");
            nn.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 ((add.value==null)||(add.value=="")){
            alert("Please Enter your Address!")
            add.focus()
            return false
            }
            if (checkAddress(add.value)==false){
            add.value=""
            alert("Invalid Adderess!");
            add.focus()
            return false
            }
            if(document.form.qua.selectedIndex==""){
            alert ( "Please select your qualification!" );
     return false;  
    }
            return true
          }
        </script>
        <form name="form" method="post" onSubmit="return validate()">
        <pre>
        Enter Name:              <input type="text" name="name" size="30"><br>
        Enter an Email Address : <input type="text" name="email" size="30"><br>
        Enter Address            <textarea name="address" rows="5" cols="23"></textarea><br>
        Select Qualification:    <select name="qua">
                                 <option value="BTech">BTech</option>
                                 <option value="MBBS">MBBS</option>
                                 <option value="MBA">MBA</option>
                                 <option value="MCA">MCA</option>
                                 </select><br>

        <input type="submit" name="Submit" value="Submit">
        </pre>
        </form>
</html>


Related Tutorials/Questions & Answers:
validations
validations  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
validations in javascript
validations in javascript  How do you check validations in javascript
Advertisements
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
Custom Validations - Struts
Custom Validations  Hi, I am trying to do the custom validations in struts 1.1.That is how can we plug in our own custom validations into Validator ? Can anybody tell me how to do this with a sample example. Thanks
Multiple Validations on jTestFields
Multiple Validations on jTestFields  Hi, I am working on an window application in which I have to validate the data of text fields, like if textbox1... then it should check whether it is valid or not. Unless all the validations
struts validations - Struts
struts validations  hi friends i an getting an error in tomcat while running the application in struts validations the error in server as validation disabled plz give me reply as soon as possible.  Hi friend
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
validations in struts - Struts
validations in struts  hi friends plz give me the solution its urgent I an getting an error in tomcat while running the application in struts validations the error in server as "validation disabled" plz give me reply as soon
Im not getting validations - Struts
Im not getting validations  I created one struts aplication im using DynaValidations I configured validation.xml and validation-rules.xml also in s-c.xml But Im unable to get validations This is my validation.xml file
Javascript validations problem
Javascript validations problem  i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation works correctly but when my validation fails i am getting an alert window and i am
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
java validations
; if (f.length<20) { alert("Address too short"); return false; } var q=document.retailer.contact_no.value; if (q==null || q=="") { alert... q=document.retailer.contact_no.value; if (q==null || q=="") { alert
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I am developing an JSP Application which supports I18N(Internationalization). In my....), how to manipulate date validations through JavaScript or Ajax? Thanks
Struts: validations code to support 2 date foramats - Struts
Struts: validations code to support 2 date foramats  What is the code in validation.xml to support 2 date formats (DD-MM-YYYY & DD/MM/YYYY ) in form. (I'm using struts 1.3
how to perform the client side validations to the dropdown list using javascript?
how to perform the client side validations to the dropdown list using javascript?  Hi Good Morning! This is Prasad, I want to perform the client side validation to the dropdown list using javascript. So give me sample.I am
how to validate javascriptcode n i am attaching file give validations
=xmlhttp.responseText; } } xmlhttp.open("GET","Ajax_Prepaid_GSM_Verification?q="+str
how to validate javascriptcode n i am attaching file give validations
","Ajax_Prepaid_GSM_Verification?q="+str,true); xmlhttp.send(); } <
how to validate javascriptcode n i am attaching file give validations
","Ajax_Prepaid_GSM_Verification?q="+str,true); xmlhttp.send(); } <
how to validate javascriptcode n i am attaching file give validations
","Ajax_Prepaid_GSM_Verification?q="+str,true); xmlhttp.send(); } <
how to validate javascriptcode n i am attaching file give validations
","Ajax_Prepaid_GSM_Verification?q="+str,true); xmlhttp.send(); } <
how to validate javascriptcode n i am attaching file give validations
","Ajax_Prepaid_GSM_Verification?q="+str,true); xmlhttp.send(); } <
Java Validations using Regular Expressions
Java Validations using Regular Expressions In this section, you will learn how to validate different fields using regular expressions. Here we have created the methods to validate the name,address, email and phone number entered
Validations using Struts 2 Annotations
Validations using Struts 2 Annotations       Validating Struts 2 Login Application using Annotations In this section we are going to validate our login application using Annotations in Action
Validations using Struts 2 Annotations
Validations using Struts 2 Annotations       Validating Struts 2 Login Application using Annotations In this section we are going to validate our login application using Annotations in Action
Struts 2 Validation
validations are integral part of any web application. With the release of Struts 2... server side validations. Struts 2.0 action relies on the XWork validation framework... is not a valid URL, it generates an error message.   Validations
Life Cycle of Java Server Faces
when validations, conversions, and events are usually handled during the life
Struts 2 Validation Example
to write validations for your Struts 2 projects. The concepts defined in this section
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
Struts
Struts   1)in struts server side validations u are using programmatically validations and declarative validations? tell me which one is better ? 2) How to enable the validator plug-in file
Prefix as A
Prefix as A   I want to know how to write validations in javascript for prefix as as letters and rest numbers.I have ACC NO A111 with A as prefix How to give validations
Java Struts - Struts
Java Struts  How can we configure the declarative validations by using the DynaValidationAction Form
codecode
codecode  hi please give me code for login page using jsp and servlets and also having validations
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
forums creation using spring with hibernate?
forums creation using spring with hibernate?  how to write mandatory fields with validations in forms using spring with hibernate? give me detailed example
validation - Struts
validation  Hi Deepak can you please tell me about struts validations perticularly on server side such as how they work whats their role etc.? thank you
validation - Struts
validation  Hi, Can you give me the instructions about validations on server side in struts.i have done client side validations for login form.but i don't want the username to be duplicated.means one username must be entered
Hi i am new to J2ee Technology and struts - Struts
Hi i am new to J2ee Technology and struts  what exatly will happen when we hit the Login button? Once we enter in to the application, what will happen. How the UserID and Password validations will done. Can any one help
 

 

 

DMCA.com