Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <script type="text/javascript" >
  2.      
  3.         function FirstNameIsValid() {
  4.      
  5.             st = document.getElementById("fname").value;
  6.            var ok=true;
  7.            if   (Number(st))
  8.            {
  9.             alert("You must enter a valid First Name(not numbers only letters!)");
  10.                 document.getElementById("fname").focus();
  11.                ok=false;
  12.                }
  13.             if (st == "") {
  14.                 alert("You must enter a First Name");
  15.                 document.getElementById("fname").focus();
  16.                ok=false;
  17.             }
  18.              return ok;
  19.         }
  20.      
  21.         function LastNameIsValid() {
  22.      
  23.             st = document.getElementById("lname").value;
  24.            var ok=true;
  25.             if   (Number(st))
  26.            {
  27.             alert("You must enter a valid Last Name(not numbers only letters!)");
  28.                 document.getElementById("fname").focus();
  29.                ok=false;
  30.                }
  31.             if (st == "") {
  32.                 alert("You must enter a last name");
  33.                document.getElementById("lname").focus();
  34.                ok=false;
  35.             }
  36.                  return ok;
  37.         }
  38.        
  39.         function AgeIsValid() {
  40.      
  41.             st = document.getElementById("yearBorn").value;
  42.             var ok=true;
  43.             if (st == "") {
  44.                 alert("You must enter an age(year)");
  45.                 document.getElementById("yearBorn").focus();
  46.                 ok=false;
  47.             }
  48.             if (isNaN(st)) {
  49.                 alert("Error, you must enter an apropriate age (year)");
  50.                document.getElementById("yearBorn").focus();
  51.              ok=false;
  52.             }
  53.             else {
  54.      
  55.                 if (Number(st) < 1930 || Number(st) > 2012) {
  56.                     alert("Enter an valid year");
  57.                     document.getElementById("yearBorn").focus();
  58.                    ok=false;
  59.                 }
  60.             }
  61.             return ok;
  62.         }
  63.        
  64.         function PhoneIsValid() {
  65.            
  66.             var st = document.getElementById("Select1").options.value + "-" + document.getElementById("tel").value;
  67.             var st2 = document.getElementById("tel").value;
  68.     var ok=true;
  69.             if (isNaN(st2)) {
  70.                 alert("Error: you must enter numbers only in phone!!");
  71.                 document.getElementById("tel").focus();
  72.                ok=false;
  73.             }
  74.      
  75.             if (st2.length != 7) {
  76.                 alert("You must enter a 7 digit number phone number");
  77.                 document.getElementById("tel").focus();
  78.               ok=false;
  79.             }
  80.      
  81.             if (st2 == "") {
  82.                 alert("You must enter a phone number");
  83.                  document.getElementById("tel").focus();
  84.                ok=true;
  85.             }
  86.            
  87.      
  88.             return ok;
  89.         }
  90.      
  91.         function EmailIsValid() {
  92.      
  93.             var stEmail = document.getElementById("email").value;
  94.             var ok=true;
  95.             if (stEmail == "") {
  96.                 alert("You must enter an email");
  97.                  document.getElementById("email").focus();
  98.                 ok=true;
  99.             }
  100.             else {
  101.                 if (stEmail.indexOf("@") < 0) {
  102.                     alert("Email must have @");
  103.                    document.getElementById("email").focus();
  104.                    ok=false;
  105.                 }
  106.                 if (stEmail.indexOf(".") < 0) {
  107.                     alert("Email must have (.)");
  108.                     document.getElementById("email").focus();
  109.                 }
  110.             }
  111.             return ok;
  112.         }
  113.  
  114.         function isvalid()
  115.         {
  116.             if ( FirstNameIsValid() && LastNameIsValid() && PhoneIsValid() && EmailIsValid() && AgeIsValid();
  117.                 return true;
  118.                 return false;
  119.         }
  120.         function submitForm()
  121.         {
  122.         if (isvalid())
  123.             form1.submit();
  124.         }
  125.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement