title: Javascript parsing an integer from a string
body: <p>What I want to do is determine if a string is numeric. I would like to know what people think about the two solutions I am trying to decide between (OR if there is a better solution that I have not found yet). The parseInt function is not suitable because it will return an integer value for a parameter like "40 years old". The two solutions I am deciding between are:  </p>
  
  <p>Use Integer.valueOf() with try catch</p>
  
  <pre><code>function isNumeric(quantity)
  {
      var isNumeric = true
      try
      {
          Integer.valueOf(quantity)
      }
      catch(err)
      {
          isNumeric = false
      }
      return isNumeric
  }
  </code></pre>
  
  <p>Or check each character individually</p>
  
  <pre><code>function IsNumeric(quantity)
  {
      var validChars = "0123456789";
      var isNumber = true;
      var nextChar;
  
      for (i = 0; i &lt; quantity.length &amp;&amp; isNumber == true; i++) 
      { 
          nexChar = quantity.charAt(i); 
          if (validChars.indexOf(nextChar) == -1) 
          {
              isNumber = false;
          }
      }
      return IsNumber;
  }
  </code></pre>
  
  <p>I would have thought there would be a simpler solution than both of these though. Have I just missed something?  </p>
  
  <p>NOTE: I am using jQuery aswel so if there is a jQuery solution that that would be sufficient</p>