Client Side Validation Using JavaScript

<html> 
<head>
<title>Form Validation</title> 
<link rel="stylesheet" type="text/css" href="style.css">

<script>
   
function formValidate()

var username = document.regform.name.value;
var userpass = document.regform.pass.value;
var useremail = document.regform.email.value;
var zipcode = document.regform.zip.value;

if( username == "" )
{
alert( "Please Enter The Name" );
return false;
}

else if( userpass == "" )
{
alert( "Please Enter The Password" );
return false;
}
       
else if( useremail == "" )
{
alert( "Please Enter The Email Address" );
 return false;
}
   
else if( zipcode == "" || isNaN( zipcode ))
{
alert( "Zip Code Allowes Only Numbers" );
return false;
}

}
</script>

</head>
<body>
<form name = "regform" onsubmit="return(formValidate());">
<table class = "tab" width="40%" align="center" bgcolor="lightgreen" cellspacing = "8" cellpadding = "8"  >         
        <tr>       
               <td><h2 align="center">Registration Form</h2></td>
            </tr>
            <tr>       
               <td><input type = "text" name = "name" placeholder="User Name" /></td>
            </tr>
             <tr>             
               <td><input type = "Password" name = "pass" placeholder="Password" /></td>
            </tr>
            <tr>       
               <td><input type = "text" name = "email" placeholder="Email Address" /></td>
            </tr>         
            <tr>         
               <td><input type = "text" name = "zip" placeholder="Zip Code #12345" /></td>
            </tr>                 
            <tr>         
               <td><input type = "submit" value = "Submit" class="btn"/></td>
            </tr>
         
</table>
</form>
</body>
</html>

Comments

Popular posts from this blog

WebPage Design Using HTML and CSS

How to design webpage using HTML And CSS

Convert XML In To Java Using Java