title: Test if field value is numeric and not empty
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10834796/validate-that-a-string-is-a-positive-integer">Validate that a string is a positive integer</a>  </p>
  </blockquote>
  
  
  
  <p>So I want to check a form field if it's empty and to allow it to has only positive numeric numbers, no spaces or letters. So far I succeed the first part to check if the field is empty with the following code:</p>
  
  <pre><code>function validate(form) {
      var elements = form.elements;
  
      if (form.qty.value == "") {
          alert("Please enter the field");
          document.forms[0].qty.focus()
          document.forms[0].qty.select()
          return false;
      }
  
      return true;
  }
  </code></pre>
  
  <p>Somewhere in the form:</p>
  
  <p><code>&lt;form action="addtocart.php" method ="post" onsubmit="return validate(this);" /&gt;</code> ...</p>
  
  <p>But now I want to allow only numbers as well as to check if the field is empty. I have found some scripts but I don't know how to merge the code into one valid script.</p>