Registration form in HTML using JAVASCRIPT validation
<html>
<head>
<title> Validation using JavaScript </title>
<script language="javascript">
function validation()
{
var x=f.un.value;
var len=x.length;
var val=x.charCodeAt(0);
var p=f.pw.value;
var c=f.cpw.value;
var a=f.email.value;
var atpos=a.indexOf("@");
var dotpos=a.lastIndexOf(".");
if(len<6 || x=='' || x==null)
{
alert("check your username ! It must be minimum 6 characters");
if(val<65 || val>90 && val<97 || val>122)
alert("username must begin with an alphabet");
return false;
}
else if(val<65 || val>90 && val <97 || val>122)
{
alert("username must begin with an alphabet");
return false;
}
else if(p=='' || c=='' || p.length<6 || c.length<6 || p!=c)
{
alert("Password and Confirm Password should be same and greater than 6 characters!");
return false;
}
else if(atpos<6 || dotpos<atpos+6 || dotpos+2>=a.length)
{
alert("Not a valid email id !!");
return false;
}
else alert("Congragulations! you have successfully registered...");
}
</script>
</head>
<body>
<h1 align=center>Welcome!! </h1>
<h2 align=center>Please register Here...</h2>
<hr width=50%>
<table align=center border=3>
<form name="f" action="home.html" onsubmit="return validation();" method="post">
<tr>
<td>User Name:</td>
<td><input type="text" name="un"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pw"/></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="cpw"/></td>
</tr>
<tr>
<td>E-mail ID:</td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</form>
</table>
</body>
</html>
<html>
<head>
<title> Validation using JavaScript </title>
<script language="javascript">
function validation()
{
var x=f.un.value;
var len=x.length;
var val=x.charCodeAt(0);
var p=f.pw.value;
var c=f.cpw.value;
var a=f.email.value;
var atpos=a.indexOf("@");
var dotpos=a.lastIndexOf(".");
if(len<6 || x=='' || x==null)
{
alert("check your username ! It must be minimum 6 characters");
if(val<65 || val>90 && val<97 || val>122)
alert("username must begin with an alphabet");
return false;
}
else if(val<65 || val>90 && val <97 || val>122)
{
alert("username must begin with an alphabet");
return false;
}
else if(p=='' || c=='' || p.length<6 || c.length<6 || p!=c)
{
alert("Password and Confirm Password should be same and greater than 6 characters!");
return false;
}
else if(atpos<6 || dotpos<atpos+6 || dotpos+2>=a.length)
{
alert("Not a valid email id !!");
return false;
}
else alert("Congragulations! you have successfully registered...");
}
</script>
</head>
<body>
<h1 align=center>Welcome!! </h1>
<h2 align=center>Please register Here...</h2>
<hr width=50%>
<table align=center border=3>
<form name="f" action="home.html" onsubmit="return validation();" method="post">
<tr>
<td>User Name:</td>
<td><input type="text" name="un"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pw"/></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="cpw"/></td>
</tr>
<tr>
<td>E-mail ID:</td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</form>
</table>
</body>
</html>
No comments:
Post a Comment