Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<html>
<head>
<script>
<!--trim fn for ignoring white spaces-->
function trim(s)
{
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
<!--Email Validation fn-->
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e)
{
var returnval=emailfilter.test(e.value)
if (returnval==false)
{
alert("Please enter a valid email address.")
e.select()
}
return returnval
}
<!--Total textbox validation-->
function validate()
{
  var vFN=trim(document.frm.FN.value);
  var vLN=trim(document.frm.LN.value);
  var vEM=trim(document.frm.EM.value);
  if(vFN=="")
  {
    alert("Enter your First Name");
    document.frm.FN.focus();
    return false;
  }
  else if(vLN=="")
  {
   alert("Enter your Last Name");
   document.frm.LN.focus();
   return false;
  }
  else if(vEM=="")
  {
   alert("Enter your Email Address");
   document.frm.EM.focus();
   return false;
  }
  else
 {
   checkmail(document.frm.EM);
   document.frm.EM.focus();
   return false;
 }
 return true;
  }

</script>
</head>
<body>
<form name="frm"  method="post" action="hi.html" onSubmit="return validate();">
<p>First Name: <input type="text" name="FN" /><br></p>
<p>Last Name: <input type="text" name="LN" /><br></p>
<p>Email Address: <input type="text" name="EM" /><br></p>
<p><input type="submit" name="goTo" value="Save"/></p>
</form>
</body>
</html>
Posted
Updated 28-Oct-10 2:28am
v2

Your code is Perfectly working for me.., There is no Error..,
 
Share this answer
 
I also saw your code is perfectly working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900