title: Identify if a string has any non-integer characters, in JavaScript
body: <p>JavaScript parseInt() does not seem to work the same way as Java parseInt().</p>
  
  <p>A very simple example is:</p>
  
  <pre><code>document.write(parseInt(" 60 ") + "&lt;br&gt;");  //returns 60
  document.write(parseInt("40 years") + "&lt;br&gt;");  //returns 40
  document.write(parseInt("He was 40") + "&lt;br&gt;");  //returns NaN
  </code></pre>
  
  <p>Line 1 is ok. but I expect line 2 to give an error, since you can't actually convert 'years' to an integer. I believe JavaScript parseInt() just checks if the first few characters in a String are an Integer.</p>
  
  <p>So how can I check that as long as there are non-Integers in the String, it will return NaN?</p>