Thursday, 16 October 2014

html registration form with validation

Posted by D. arunkumar  |  3 comments

 <script type="text/javascript" src="">  
 function validate()  
 {  
      var d=document.register;  
      var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;  
      if(d.cn.value == '')  
      {  
           alert("Enter Name");  
           d.cn.focus();  
           return false;  
      }  
      if(d.cn.value.length<=2)  
      {  
      alert("Minimum Name Should be greater than two");  
      return false;       
      }  
      if(d.email.value == '')  
      {  
      alert("Email is is Required");  
      d.email.focus();  
      return false;       
      }  
      if(reg.test(d.email.value) == false)  
      {  
      alert("Invalid Email");  
      return false;       
      }  
      if(d.password.value == '')  
      {  
      alert("Password is is Required");  
      d.password.focus();  
      return false;       
      }  
      if(d.password.value != d.cpassword.value)  
      {  
      alert("Passwords Mismatch")  
      return false;       
      }  
      if(d.year.value == 1)  
      {  
      alert("Select Year");  
      return false;       
      }  
      if(d.gender[0].checked == false && d.gender[1].checked == false)  
      {  
      alert("Select Gender");  
      return false;       
      }  
      if(d.terms.checked == false)  
      {  
      alert("Accept terms");  
      return false;       
      }  
 }  
 </script>  
 <form name="register" method="post" onSubmit="return validate()">  
 <table width="200" border="1" align="center">  
  <tr>  
   <td>CompanyName<span style="color:red">*</span>:</td>  
   <td><input type="text" name="cn" id="cn"></td>  
  </tr>  
  <tr>  
   <td>Email<span style="color:red">*</span>:</td>  
   <td><input type="text" name="email" id="email"></td>  
  </tr>  
  <tr>  
   <td>Password<span style="color:red">*</span>:</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>Year<span style="color:red">*</span>:</td>  
   <td>  
   <select name="year" id="year">  
   <option value="1">Select</option>  
   <?php for($i=1999;$i<=date(Y);$i++) { ?>  
   <option value="<?php echo $i ?>"><?php echo $i ?></option>  
   <?Php } ?>  
   </select>  
   </td>  
  </tr>  
  <tr>  
   <td>Gender<span style="color:red">*</span>:</td>  
   <td><input type="radio" name="gender" id="gender">Male  
   <input type="radio" name="gender" id="gender">FeMale</td>  
  </tr>  
  <tr>  
  <td colspan="2"><input type="checkbox" name="terms" id="terms">  
  I Accepted the <a href="terms.php">terms&conditions</a></td>  
  </tr>  
  <tr>  
   <td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Register"></td>  
  </tr>  
 </table>  
 </form>  

08:10 Share:

3 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top