title: JavaScript - Test for an integer
body: <p>I have a text field that allows a user to enter their age. I am trying to do some client-side validation on this field with JavaScript. I have server-side validation already in place. However, I cannot seem to verify that the user enters an actual integer. I am currently trying the following code:</p>
  
  <pre><code>    function IsValidAge(value) {
          if (value.length == 0) {
              return false;
          }
  
          var intValue = parseInt(value);
          if (intValue == Number.NaN) {
              return false;
          }
  
          if (intValue &lt;= 0)
          {
              return false;
          }
          return true;
      }
  </code></pre>
  
  <p>The odd thing is, I have entered individual characters into the textbox like "b" and this method returns true. How do I ensure that the user is only entering an integer?</p>
  
  <p>Thank you</p>