Tuesday 9 July 2013

Registration Form in PHP using Java Script Validations

// Registration Form in PHP using Java Script Validations

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
.regfirm {
font-size: 20px;
color: #0033FF;
}
.star {
color: #F00;
}
</style></head>

<body>
 <script type="text/javascript">
function uservalid()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;
var uid=document.form1.uid.value;
var password=document.form1.pass.value;
var pexpnum=/^(?=.*[0-9])/;
var pexpcap=/^(?=.*[A-Z])/;
var pexpsm=/^(?=.*[a-z])/;
var cpass=document.form1.cpass.value;
var dob=document.form1.dob.value;
var phno=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
var email=document.form1.email.value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
var address=document.form1.addr.value;
if(name=="")
{
alert("Please Enter Your Name");
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
alert("Please Enter Valid Name");
document.form1.name.focus();
return false;
}
else if(uid=="")
{
alert("Please Enter User Id");
document.form1.uid.focus();
return false;
}
else if(uid.length<5)
{
alert("User Id Minimum 5 letters");
document.form1.uid.focus();
return false;
}

else if(password=="")
{
alert("Please Enter Password");
document.form1.pass.focus();
return false;
}
else if(password.length<6)
{
alert("Password must be more than 6 letters");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpnum))
{
alert("Password contain atleast one Number");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpcap))
{
alert("Password contain atleast one Capital letter");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpsm))
{
alert("Password contain atleast one Small letter");
document.form1.pass.focus();
return false;
}
else if(cpass=="")
{
alert("Please Enter Conform Password");
document.form1.cpass.focus();
return false;
}
else if(password!=cpass)
{
alert("Password and Conform password must be same");
document.form1.cpass.focus();
return false;
}
else if(dob=="")
{
alert("Please Enter Date Of Birth");
document.form1.dob.focus();
return false;
}
else if(phno=="")
{
alert("Please Enter Phone no");
document.form1.mobile.focus();
return false;
}
else if(!phno.match(phexp))
{
alert("Enter Valid Phone no");
document.form1.mobile.focus();
return false;
}
else if(phno.length!=10)
{
alert("Enter 10 digit Phone no");
document.form1.mobile.focus();
return false;
}
else if(email=="")
{
alert("Please Enter Email Id");
document.form1.email.focus();
return false;
}
else if(atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
alert("Enter Valid Email Id EX: abc@d.com");
document.form1.email.focus();
return false;
}
   else if ( ( document.form1.gender[0].checked == false ) && ( document.form1.gender[1].checked == false ) )
   {
        alert ( "Please choose Your Gender" );
        document.form1.gender[0].focus();
        return false;
    }
else if(address=="")
{
alert("Please Enter Your Full Address");
document.form1.addr.focus();
return false;
}


}
</script>

<table width="562" border="0" align="center" vspace="0px">
  <tr>
    <td>
    <form name="form1" id="form1" method="post" action="" onsubmit="return uservalid()"><table width="500" border="0" align="center">
      <tr>
        <td colspan="2" align="center"><span class="regfirm">Registraion Form</span></td>
      </tr>
      <tr>
        <td width="135">Name <label class="star">*</label></td>
        <td width="234" height="35"><input type="text" name="name" id="name" placeholder="Enter Your Full Name" /></td>
      </tr>
      <tr>
        <td>User Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="uid" id="uid" placeholder="Enter Your User Id" /></td>
        </tr>
      <tr>
        <td>Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="pass" id="pass" placeholder="Create New Password" /></td>
        </tr>
      <tr>
        <td>Conform Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="cpass" id="cpass" placeholder="Enter Same Password " /></td>
        </tr>
      <tr>
        <td>Date Of Birth <label class="star">*</label></td>
        <td height="35"><input type="date" name="dob" id="dob" /></td>
        </tr>
      <tr>
        <td>Contact Number <label class="star">*</label></td>
        <td height="35"><input type="text" name="mobile" id="mobile" placeholder="Enter Your Contact Number" /></td>
        </tr>
      <tr>
        <td>Email Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="email" id="email" placeholder="Enter Your Email Id" /></td>
        </tr>
      <tr>
        <td>Gender <label class="star">*</label></td>
        <td><p>
          <label>
            <input type="radio" name="gender" value="male" />
            Male</label>
          <br />
          <label>
            <input type="radio" name="gender" value="female" />
            Female</label>
          <br />
        </p></td>
        </tr>
      <tr>
        <td>Address <label class="star">*</label></td>
        <td><textarea name="addr" id="addr" cols="25" rows="3" placeholder="Enter Your Full Address" style="resize:none"></textarea></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2"><table width="358" border="0">
          <tr>
            <td width="104">&nbsp;</td>
            <td width="95"><input type="submit" name="submit" id="submit" value="Submit" /></td>
            <td width="103"><input type="reset" name="reset" id="reset" value="Reset" /></td>
            <td width="38">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
      </table>
    </form></td>
  </tr>
  <tr>
  <td height="30" align="center" bgcolor="#3850AF">Copy Rights&copy;Narsi Reddy 2013</td>
  </tr>
</table>
</body>
</html>

1 comment: