<html>
<head>
<title>Form Validation Primer Tutorial</title>
<script>
function init() {
 if (window.location.search.indexOf("hone") != (0 - 1) && 
     window.location.search.indexOf("Name=&Email=&Phone=") == (0 - 1)) {
   var myprmstr = window.location.search.substr(1);
   var myprmarr = myprmstr.split ("&");
   var myparams = {};
   var stuff = "Welcome\n\n";
   for ( var i = 0; i < myprmarr.length; i++) {
    var mytmparr = myprmarr[i].split("=");
    myparams[mytmparr[0]] = mytmparr[1];
    stuff = stuff + mytmparr[0] + " is ";
    stuff = stuff + mytmparr[1].replace("%40","@").replace("+"," ") + "\n";
    document.getElementById(mytmparr[0]).value = 
        mytmparr[1].replace("%40","@").replace("+"," ");
   } 
   alert(stuff);
 } else {
   document.forms[0].onsubmit = function() { return validateform(); }
 }
}
function validateform() {
 var nameok  = validatename(document.getElementById('Name').value);
 var emailok = validateemail(document.getElementById('Email').value);
 var phoneok = validatephone(document.getElementById('Phone').value);
 return nameok && emailok && phoneok;
}
function validatename(nme) {
 if (nme.length == 0) {
   alert("Invalid name ... try again.");
   return false;
 }
 return true;
}
function validateemail(eml) {
 var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 if (re.test(eml) == false) {
   alert("Invalid email ... try again.");
   return false;
 }
 return true;
}
function validatephone(phn) {
 var re = /^\(?(\d{2,3})\)?[\.\-\/ ]?(\d{4})[\.\-\/ ]?(\d{4})$/;
 if (re.test(phn) == false) {
   alert("Invalid telephone number (please include area code) ... try again.");
   return false;
 }
 return true;
}
</script>
<body onload="init();" style="background-color: yellow;">
<form style="border: 5px solid blue; padding: 4px 4px 4px 4px;">
<h2>Your Details</h2>
<p><label>Name: * 
<input type="text" id="Name" name="Name" size="50" /></label></p>
<p><label>Email: * 
<input type="text" id="Email" name="Email" size="50" /></label></p>
<p><label>Phone: * 
<input type="text" id="Phone" name="Phone" size="50" /></label></p>
<p><input id="r" type="reset" /> <input type="submit" id="s" value="Submit" /></p>
</form>
</body>
</html>