Loading
View RSS Feed

technotarun

How To Do Form Validation Using Java Script?

Rating: 4 votes, 4.50 average.
HTML Code:
<html>
	<head>
		<script type="text/javascript">
		var n,p,cfp,e;
		function validate(f1)
		{
			
			n=document.f1.name.value;
			p=document.f1.pass.value;
			cfp=document.f1.cpass.value;
		 	e=document.f1.email.value.indexOf("@");
			if(n.length==0)
			{
				alert("Please enter a name");
				return false;
			}	
			
			if(p.length==0)
			{
			 	alert("Please enter a password");
				return false;
			}
			
			if(p.length>8)
			{
				alert("the max length allowed for password is 8");
				return false;
			}
			
			if(p!=cfp)
			{
				alert("the password do not match");
				return false;
			}
			
			if(e==-1)
			{
				alert("the email id entered is invalid");
				return false;
			}
		return true;

			
		}	

		</script>
	</head>
<form name="f1" onsubmit="return validate()" method="post" action="a1.html">
<body bgcolor=#AB78CD><center>
	<br>
	<br>
		
		
	
		<table><tr><td>USERNAME::</td><td><input type="text" name="name"></td></tr>
		<tr><td>PASSWORD::</td><td><input type="password" name="pass"></td></tr>
		<tr><td>CONFIRM PASSWORD::</td><td><input type="password" name="cpass"></td></tr>
		<tr><td>EMAIL ID::</td><td><input type="text" name="email"></td></tr></table>
		
		
	<br>
	<br>
	<br>
		<input type="submit" name="but" value="submit"></center>
</body>
</form>
</html>

Submit "How To Do Form Validation Using Java Script?" to Digg Submit "How To Do Form Validation Using Java Script?" to del.icio.us Submit "How To Do Form Validation Using Java Script?" to StumbleUpon Submit "How To Do Form Validation Using Java Script?" to Google

Updated 02-24-2011 at 07:00 PM by Harsh

Categories
Java , Web Design

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.