1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To Validate In JavaScript?

Discussion in 'JavaScript and AJAX' started by angad_aks, Feb 15, 2011.

  1. angad_aks

    angad_aks Banned

    Joined:
    Feb 15, 2011
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    		function validate()
    		{
    			namein=document.forms[0].name1.value
    			indexin=document.forms[0].email.value.indexOf('@')
    			passin=document.forms[0].passin.value
    			passin1=document.forms[0].passin1.value
    				if(namein.length==0)
    				{
    					alert("Invalid name,plz re-enter")
    				}
    				if(indexin==-1)
    				{
    					alert("The Email ID entered by you is invalid")
    					return false
    				}
    				if(passin.length<8)
    				{
    					alert("Too short password,plz re-enter")
    					return false
    				}
    				if(passin!=passin1)
    				{
    					alert("Password mismatch")
    					return false
    				}
    				return true
    				
    		}
    		</script>
    	</head>
    	<body bgcolor="cyan">
    	<center><font color="redgreenblue"><h2>VALIDATION FORM</h2></center><br><br>
    	<form name="resume" onsubmit="return validate()">
    	<center><table>
    	<tr><td>ENTER YOUR FIRST NAME:</td>
    	<td><input type="text" name="name1" maxlength=100></td></tr>
    	<tr><td>ENTER YOUR EMAIL-ID:</td>
    	<td><input type="text" name="email" maxlength=100></td></tr>
    	<tr><td>ENTER YOUR PASSWORD:</td>
    	<td><input type="password" name="passin" maxlength=30></td></tr>
    	<tr><td>RETYPE YOUR PASSWORD:</td>
    	<td><input type="password" name="passin1" maxlength=30></td></tr>
    	</table></center><br><br><br><br><br><br><br>
    	<center><input type="submit" value="proceed"></center>
    	</form>
    	</body>
    </html>			
    			
    			
    		
    		
    
    
    
    
    
    
    
     

Share This Page