
write a javascript program to create a application form with validation?

hi banupriya,
I hope this example will helpful for you.
<html>
<head>
<title>Form Validation Example</title>
<script type="text/javascript">
function formValidator()
{
var nm=document.forms["form1"]["name"].value;
var em = document.forms["form1"]["email"].value;
var atpos = em.indexOf("@");
var dotpos = em.lastIndexOf(".");
var mn = document.forms["form1"]["mob"].value;
var mobNumLen = document.forms["form1"]["mob"].value.length;
if(nm == "" || nm == null)
{
alert( "Name Field must not be empty" );
document.form1.name.focus() ;
return false;
}
if(em == null || nm=="")
{
alert("Email field must not be empty");
document.form1.email.focus();
return false;
}
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=em.length)
{
alert("Enter proper e-mail address");
document.form1.email.focus();
return false;
}
if(mn == "" || mn == null || isNaN(mn) ||
mn.length < 10 || mn.length >10 )
{
alert( "Mobile Number must be in the format ##### and of minimum 10 digits" );
document.form1.mob.focus() ;
return false;
}
return( true );
}
</script>
<body>
<form action="success.html" name="form1" onsubmit="return formValidator();">
<table border="1">
<tr>
<td>Name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>EMail</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type="text" name="mob" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.