<script type="text/javascript">
function checkForm(reg_form)
{
if(reg_form.name.value == "")
{
alert("Error: Name cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.name.value))
{
alert("Error: Name must contain only letters, numbers and underscores!");
reg_form.name.focus();
return false;
}
if(reg_form.u_rollno.value == "")
{
alert("Error: university rollno cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.name.value))
{
alert("Error: University roll no must contain only letters, numbers and underscores!");
reg_form.name.focus();
return false;
}
if(reg_form.sem.value == "")
{
alert("Error: Semester cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.sem.value))
{
alert("Error: Semester must contain only letters, numbers and underscores!");
reg_form.sem.focus();
return false;
}
if(reg_form.branch.value == "")
{
alert("Error: branch cannot be blank!");
reg_form.branch.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.branch.value))
{
alert("Error: branch must contain only letters, numbers and underscores!");
reg_form.branch.focus();
return false;
}
if(reg_form.c_id.value == "")
{
alert("Error: College id cannot be blank!");
reg_form.c_id.focus();
return false;
}
var x = document.forms["reg_form"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Not a valid e-mail address");
return false;
}
if(reg_form.password.value != "" && reg_form.password.value == reg_form.c_password.value)
{
if(reg_form.password.value.length < 6)
{
alert("Error: Password must contain at least six characters!");
reg_form.password.focus();
return false;
}
if(reg_form.password.value == reg_form.name.value)
{
alert("Error: Password must be different from Username!");
reg_form.password.focus();
return false;
}
re = /[0-9]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one number (0-9)!");
reg_form.password.focus();
return false; }
re = /[a-z]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one lowercase letter (a-z)!");
reg_form.password.focus();
return false;
}
re = /[A-Z]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one uppercase letter (A-Z)!");
reg_form.password.focus();
return false;
}
}
else
{
alert("Error: Please check that you've entered and confirmed your password!");
reg_form.password.focus();
return false;
}
}
</script>
<center>
<table cellpadding="10" cellspacing="10">
<form action="reg_action.php" onSubmit="return checkForm(this);" method="post" name="reg_form">
<tr>
<td>Name:</td>
<td><input type="text" size="20" name="name" /></td>
</tr>
<tr>
<td>University Roll No:</td>
<td><input type="text" size="20" name="u_rollno" /></td>
</tr>
<td>Semester:</td>
<td><input type="text" size="20" name="sem" /></td>
</tr>
<tr>
<td>Branch:</td>
<td><input type="text" size="20" name="branch" /></td>
</tr>
<tr>
<td>College id:</td>
<td><input type="text" size="20" name="c_id"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" size="20" name="email" /></td>
</tr>
<tr>
<td>Phone No:</td>
<td><input type="text" size="20" name="phone_no" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" size="20" name="password" /></td>
</tr>
<tr>
<td>Conform Pssword:</td>
<td><input type="password" size="20" name="c_password" /></td>
</tr>
<tr>
<tr>
<td></td>
<td><input type="submit" value="REGISTER" > <input type="reset" value="RESET"></td>
</tr>
</form>
</table>
</center>
</html>
function checkForm(reg_form)
{
if(reg_form.name.value == "")
{
alert("Error: Name cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.name.value))
{
alert("Error: Name must contain only letters, numbers and underscores!");
reg_form.name.focus();
return false;
}
if(reg_form.u_rollno.value == "")
{
alert("Error: university rollno cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.name.value))
{
alert("Error: University roll no must contain only letters, numbers and underscores!");
reg_form.name.focus();
return false;
}
if(reg_form.sem.value == "")
{
alert("Error: Semester cannot be blank!");
reg_form.name.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.sem.value))
{
alert("Error: Semester must contain only letters, numbers and underscores!");
reg_form.sem.focus();
return false;
}
if(reg_form.branch.value == "")
{
alert("Error: branch cannot be blank!");
reg_form.branch.focus();
return false;
}
re = /^\w+$/;
if(!re.test(reg_form.branch.value))
{
alert("Error: branch must contain only letters, numbers and underscores!");
reg_form.branch.focus();
return false;
}
if(reg_form.c_id.value == "")
{
alert("Error: College id cannot be blank!");
reg_form.c_id.focus();
return false;
}
var x = document.forms["reg_form"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Not a valid e-mail address");
return false;
}
if(reg_form.password.value != "" && reg_form.password.value == reg_form.c_password.value)
{
if(reg_form.password.value.length < 6)
{
alert("Error: Password must contain at least six characters!");
reg_form.password.focus();
return false;
}
if(reg_form.password.value == reg_form.name.value)
{
alert("Error: Password must be different from Username!");
reg_form.password.focus();
return false;
}
re = /[0-9]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one number (0-9)!");
reg_form.password.focus();
return false; }
re = /[a-z]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one lowercase letter (a-z)!");
reg_form.password.focus();
return false;
}
re = /[A-Z]/;
if(!re.test(reg_form.password.value))
{
alert("Error: password must contain at least one uppercase letter (A-Z)!");
reg_form.password.focus();
return false;
}
}
else
{
alert("Error: Please check that you've entered and confirmed your password!");
reg_form.password.focus();
return false;
}
}
</script>
<center>
<table cellpadding="10" cellspacing="10">
<form action="reg_action.php" onSubmit="return checkForm(this);" method="post" name="reg_form">
<tr>
<td>Name:</td>
<td><input type="text" size="20" name="name" /></td>
</tr>
<tr>
<td>University Roll No:</td>
<td><input type="text" size="20" name="u_rollno" /></td>
</tr>
<td>Semester:</td>
<td><input type="text" size="20" name="sem" /></td>
</tr>
<tr>
<td>Branch:</td>
<td><input type="text" size="20" name="branch" /></td>
</tr>
<tr>
<td>College id:</td>
<td><input type="text" size="20" name="c_id"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" size="20" name="email" /></td>
</tr>
<tr>
<td>Phone No:</td>
<td><input type="text" size="20" name="phone_no" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" size="20" name="password" /></td>
</tr>
<tr>
<td>Conform Pssword:</td>
<td><input type="password" size="20" name="c_password" /></td>
</tr>
<tr>
<tr>
<td></td>
<td><input type="submit" value="REGISTER" > <input type="reset" value="RESET"></td>
</tr>
</form>
</table>
</center>
</html>
No comments:
Post a Comment