<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>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)