Advertisement
f0rkB0mb

FirstVal Tolentino Babon's code

Nov 30th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.17 KB | None | 0 0
  1. <script type='text/javascript'>
  2. function formValidator(){
  3.     var firstname = document.getElementById('firstname');
  4.     var lastname = document.getElementById('lastname');
  5.     var addr = document.getElementById('addr');
  6.     var country = document.getElementById('country');
  7.     var email = document.getElementById('email');
  8.     var number = document.getElementById('number');
  9.  
  10.     if(isAlphabet(firstname, "Please enter only letters for your name")){
  11.         if(isAlphabet(lastname, "Please enter only letters for your lastname")){
  12.             if(isAlphabet(addr, "Numbers and Letters Only for Address")){
  13.                 if(madeSelection(country, "Please Choose a Country")){
  14.                     if(emailValidator(email, "Please enter a valid email address")){
  15.                         if(isNumeric(number, "Please enter numbers only")){
  16.                             return true;
  17.                         }
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.     }
  23.     return false;
  24. }
  25. function notEmpty(elem, helperMsg){
  26.     if(elem.value.length == 0){
  27.         alert(helperMsg); elem.focus();
  28.         return false;
  29.     }
  30.     return true;
  31. }
  32.  
  33. function isNumeric(elem, helperMsg){
  34.     var numericExpression = /^[0-9]+$/;
  35.     if(elem.value.match(numericExpression)){
  36.         return true;
  37.     }else{
  38.         alert(helperMsg);
  39.         elem.focus();
  40.         return false;
  41.     }
  42. }
  43.  
  44. function isAlphabet(elem, helperMsg){
  45.     var alphaExp = /^[a-zA-Z]+$/;
  46.     if(elem.value.match(alphaExp)){
  47.         return true;
  48.     }else{
  49.         alert(helperMsg);
  50.         elem.focus();
  51.         return false;
  52.     }
  53. }
  54.  
  55. function isAlphanumeric(elem, helperMsg){
  56.     var alphaExp = /^[0-9a-zA-Z]+$/;
  57.     if(elem.value.match(alphaExp)){
  58.         return true;
  59.     }else{
  60.         alert(helperMsg);
  61.         elem.focus();
  62.         return false;
  63.     }
  64. }
  65.  
  66. function madeSelection(elem, helperMsg){
  67.     if(elem.value == "Please Choose"){
  68.         alert(helperMsg);
  69.         elem.focus();
  70.         return false;
  71.     }else{
  72.         return true;
  73.     }
  74. }
  75.  
  76.  
  77. function emailValidator(elem, helperMsg){
  78.     var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
  79.     if(elem.value.match(emailExp))
  80.     {
  81.         return true;
  82.     }else{
  83.         alert(helperMsg);
  84.         elem.focus();
  85.         return false;
  86.     }
  87. }
  88. </script>
  89.  
  90. <form onsubmit='return formValidator()' >
  91.     <table border=1>
  92.         <tr><td>First Name: <td><input type='text' id='firstname' />
  93.         <tr><td>Last Name: <td><input type='text' id='lastname' />
  94.         <tr><td>Date of Birth:<td>
  95.         <select>
  96.             <option>Month</option>
  97.             <option>January</option>
  98.             <option>February</option>
  99.             <option>March</option>
  100.             <option>April</option>
  101.             <option>May</option>
  102.             <option>June</option>
  103.             <option>July</option>
  104.             <option>August</option>
  105.             <option>September</option>
  106.             <option>October</option>
  107.             <option>November</option>
  108.             <option>December</option>
  109.         </select>
  110.         <select>
  111.             <option>Day</option>
  112.             <option>1</option>
  113.             <option>2</option>
  114.             <option>3</option>
  115.             <option>4</option>
  116.             <option>5</option>
  117.             <option>6</option>
  118.             <option>7</option>
  119.             <option>8</option>
  120.             <option>9</option>
  121.             <option>10</option>
  122.             <option>11</option>
  123.             <option>12</option>
  124.             <option>13</option>
  125.             <option>14</option>
  126.             <option>16</option>
  127.             <option>17</option>
  128.             <option>18</option>
  129.             <option>20</option>
  130.             <option>21</option>
  131.             <option>22</option>
  132.             <option>23</option>
  133.             <option>24</option>
  134.             <option>25</option>
  135.             <option>26</option>
  136.             <option>27</option>
  137.             <option>28</option>
  138.             <option>29</option>
  139.             <option>30</option>
  140.             <option>31</option>
  141.         </select>
  142.         <select>
  143.             <option>Year</option>
  144.             <option>2013</option>
  145.             <option>2012</option>
  146.             <option>2011</option>
  147.             <option>2010</option>
  148.             <option>2009</option>
  149.             <option>2008</option>
  150.             <option>2007</option>
  151.             <option>2006</option>
  152.             <option>2005</option>
  153.             <option>2004</option>
  154.             <option>2003</option>
  155.             <option>2002</option>
  156.             <option>2001</option>
  157.             <option>2000</option>
  158.             <option>1999</option>
  159.             <option>1998</option>
  160.             <option>1997</option>
  161.             <option>1996</option>
  162.             <option>1995</option>
  163.             <option>1994</option>
  164.             <option>1993</option>
  165.             <option>1992</option>
  166.             <option>1991</option>
  167.             <option>1990</option>
  168.             <option>1989</option>
  169.             <option>1988</option>
  170.             <option>1987</option>
  171.             <option>1986</option>
  172.             <option>1985</option>
  173.             <option>1984</option>
  174.             <option>1983</option>
  175.             <option>1982</option>
  176.             <option>1981</option>
  177.             <option>1980</option>
  178.         </select>
  179.         <tr><td>Gender:<td><input type="Radio" name="Group1" value="Male" />Male <input type="Radio" name="Group1" value="Female" />Female
  180.         <tr><td>Address:<td><textarea cols="20" rows="5" id='addr'/></textarea>
  181.         <tr><td>Country: <td>
  182.         <select id='country'>
  183.             <option>Choose Country</option>
  184.             <option>Philippines</option>
  185.             <option>United States</option>
  186.             <option>Peru</option>
  187.             <option>Brazil</option>
  188.             <option>India</option>
  189.             <option>Alaska</option>
  190.             <option>Venezuela</option>
  191.             <option>Mexico</option>
  192.             <option>Los Angeles</option>
  193.             <option>Mecaragua</option>
  194.             <option>America</option>
  195.             <option>Australia</option>
  196.             <option>United Kingdom</option>
  197.             <option>Thailand</option>
  198.             <option>United States</option>
  199.         </select>
  200.         <tr><td>Email: <td><input type='text' id='email' />
  201.         <tr><td>Mobile:<td><input type="text" id="number" />
  202.         <tr><td><input type='submit' value='submit' /><input type='reset' value='clear' />
  203.     </table>
  204. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement