title: Validating age field
body: <p>I'm trying to validate an age field in a form but I'm having some problem. First I tried to make sure that the field will not be send empty. I don't know JavaScript so I searched some scripts and adapted them to this:</p>
  
  <pre><code>function isInteger (s)
  {
    var i;
    if (isEmpty(s))
      if (isInteger.arguments.length == 1)
        return 0;
      else
        return (isInteger.arguments[1] == true);
  
    for (i = 0; i &lt; s.length; i++)
    {
      var c = s.charAt(i);
      if (!isDigit(c))
        return false;
    }
  
    return true;
  }
  
  function isEmpty(s)
  {
    return ((s == null) || (s.length == 0))
  }
  
  function validate_required(field,alerttxt)
  {
    with (field)
    {
      if (value==null||value=="")
      {
        alert(alerttxt);return false;
      }
      else
      {
        return true;
      }
    }
  }
  
  function validate_form(thisform)
  {
    with (thisform)
    {
      if  ((validate_required(age,"Age must be filled out!")==false) ||      
          isInteger(age,"Age must be an int number")==false))
      {email.focus();return false;}
    }
  }
  
  //html part
  &lt;form action="doador.php" onsubmit="return validate_form(this)" method="post"&gt;
  </code></pre>
  
  <p>It's working fine for empty fields, but if I type any letters or characters in age field, it'll be sent and saved a 0 in my database. Can anyone help me?</p>
  
  <p>Sorry for any mistake in English, and thanks in advance for your help.</p>