Share on Google+Share on Google+

kamal chanda
REGISTARTION FORM VALIDADTION
1 Answer(s)      4 years and 5 months ago
Posted in : JavaScript Questions
Hiee..
actually i have developed a sign up page where the details get stored in to database after registration. So i want to validate the user details during the signing up process whether the user name is already registered or not... if the user name exist in the data base i should get an alert that user name is already regstrd please choose new username... pls help me...


MY CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function validateForm()
{
//var x=document.forms["myform"]["funame"].value;
var x=document.getElementById("funame").value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }

  var a=document.getElementById("luname").value;
  if (a==null || a=="")
  {
  alert("Last name must be filled out");
  return false;
  }
  var y=document.getElementById("password").value;
  var z=document.getElementById("cpassword").value;
  if(y!=z)
  {
alert("Idiot password and confirm password doesnot match");
return false;
  }
}
</script>
</head>
<body bgcolor=#1F3D4C>
<form name="myform" action="urlpat" method="post" onsubmit="return validateForm()">
<div id="container" style="width:500px">

<div id="header" style="background-color:#66293D;">
<h1 style="margin-bottom:0;width=1500;">SPARK REGISTARTIONS</h1></div>

<table align="center">
<th><h1>SIGN UP<h1></th>

<tr><td>enter first name:</td><td><input type="text"  name="funame" id="funame"></td></tr>
<tr><td>enter last name:</td><td><input type="text" name="luname" id="luname"></td></tr>
<tr><td>enter user name:</td><td><input type="text" name="username"></td></tr>
<tr><td>choose password:</td><td><input type="password" name="password" id="password"></td></tr>
<tr><td>confirm password:</td><td><input type="password" name="cpassword" id="cpassword"></td></tr>
<tr><td>enter fathers name:</td><td><input type=text name="fathername"></td></tr>
<tr><td>enter ur emailid</td><td><input type="text" name="emailid"></td></tr>
</table><center>
<h4>Gender</h4>
Male<input type="radio" name="gender" value="male">
Female <input type="radio" name="gender" value="female"><br>
<h4>select your country</h4>
<select name="country">
<option value="india">INDIA</option>
<option value="australia">AUSTRALIA</option>
<option value="usa">USA</option>
<option value="srilanka">SRILANKA</option>
<option value="france">FRANCE</option>
<option value="china">CHINA</option><br>
</select>
<table align="center">
<th><h4>select your programming skills</h4></th>
<tr><td><input type="checkbox" name="programming concepts" value="java">java</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value="c">c</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value="c++">c++</td></tr>
<tr><td><input type="checkbox" name="programming concepts" value=".net">MS.NET</td></tr>
</table>
<input type="submit" value="submit"></br>
<h4>If Registered User please Sign In</h4>
<a href="signin.html" "background-color:#002233;">SIGN IN</a>
</div>
</form></center>
</body>
</html>

Ads

View Answers

November 2, 2012 at 3:52 PM


Here is a code that validates fields of html form using javascript.

<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:
REGISTARTION FORM VALIDADTION
REGISTARTION FORM VALIDADTION  Hiee.. actually i have developed a sign up page where the details get stored in to database after registration. So i...;body bgcolor=#1F3D4C> <form name="myform" action="urlpat" method="post
form
form   Can I prevent a form from being submitted again
Advertisements
form validation
form validation  how the form validation is done in jsf form using javaScript
print a form of *
print a form of *   * *** ***** ******* ********* ******* ***** *** *   Post the format properly
Multipage form
Multipage form  I have a multipage form in php with 2 pages wnhen i submit the form data from both the pages should go in database how should i pass teh data from 1st page to 2nd page and then put the entire form data in mysql
jsp form
jsp form  hi sir, one got one got in jsp form after entering the data into the form the data is not saving in the database i will send you code of two forms if dnt understand my problem
submit a form
submit a form  How can we submit a form without a submit button
Form handling
Form handling  I created a spring project. I created a jsp...;form:form name="loginForm" modelAttribute="loginForm" method="get"> <...;/td> <td> <form:input path="username"/>
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
Form validation
Form validation  Hi Everyone Can someone assist me with a complete code to validate a form. e.g where the user must insert an ID number it should check if the user entered the correct data and within a valid range. This must
PHP form
PHP form  Hi Sir/Madam, I am developing an attendance form using php, which displays the name and ID of a Employees which are fetched from Db and I... form and update them to respective coloumn... Please any one help mo out please
Employee form
Employee form  In employee form emp Id id after any data iserted is incremented for oher data insertion. insert, delete, update buttons when we cleak the select buttoun then the created table data iserted automaticaly
other form
other form  Can I write this code in other form: if (quantity>=5) { System.out.println("Congrats!! You get a discount of 5%."); } else { System.out.println("you can avail a discount of 5% when you make a purchase of 5 items
struts form
struts form  Hi, This is Rajesh.I'm creating struts form in jsp.i have two textboxes in my jsp.During Jsp page loading focus will automatically should come to second textbox(That means during page loading cursor automatically
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components prepsent in that form are getting clearedup using frameobject.setVisible(false
login form
login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components prepsent in that form are getting clearedup using frameobject.setVisible(false
Login Form
of +,on clicking which a login form appears. Only the middle column is different
Login Form
of +,on clicking which a login form appears. Only the middle column is different
form submission
form submission  I have two pairs of textboxes...( so in total 4...("Enter text4 value!"); return false; } return true; } </script> <form name="form" method="post" onsubmit="return validate();"> <input type="text
jsp form
jsp form  hai... GoodEvening I have one doubt on jsp.please wil u clarify it. how to move one jsp form to another jsp form with out using forward...)form1.jsp: <html> <form method="post" action="form2.jsp"> <table>
form validation
form validation  <form name="form" method="post" action="process.php" onsubmit="return validate(); "> <table align="center" border="1px" bgcolor="orange" > <tr><td>username:</td><
about form
about form  how to dynamically increase the textbox in the 2nd form when i gave any value in textbox of form1 . if i gave 5 in the textbox of form1 , totally 5textbox have to be created in form2.   import javax.swing.
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i... button wich once clicked we have a new list created on the same form. Thank you...); } } </script> <form method="post" action="" name="form1"> <
Dynamic form
Dynamic form  I need to make a dynamic form using jsp for example, i will need a list of items which when we select one option another list... clicked we have a new list created on the same form. Thanks for your help  
jsp form
jsp form  hi i have one excuted jsp form.and in that the data should be dispaly on another jsp form.please help me thanks in advance   Hi Friend, Try this: 1)form1.jsp: <html> <form method="post" action
registration form
="center" border=0&gt; &lt;form name="f1" action="CreateUser
JavaScript Form Validation
JavaScript Form Validation  JavaScript Form Validation
The form tag
In this tutorial, you will learn about Spring form tag
form field issue
form field issue  how to set the values in form field and form field drop down (doc 2007) using Apache poi
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads