title: Javascript Regex for decimals
body: <p>In Javascript, I am trying to validate a user input to be only valid decimals</p>
  
  <p>I have the following JSFiddle that shows the regex I currently have</p>
  
  <p><a href="http://jsfiddle.net/FCHwx/" rel="nofollow noreferrer">http://jsfiddle.net/FCHwx/</a></p>
  
  <pre><code>var regex = /^[0-9]+$/i;
  
  var key = '500.00';
  
  if (key.match(regex) != null) {
      alert('legal');
  }
  else {
      alert('illegal');
  }
  </code></pre>
  
  <p>This works fine for integers. I need to also allow decimal numbers (i.e. up to 2 decimal places)</p>
  
  <p>I have tried many of the regex's that can be found on stackoverflow
  e.g.
  <a href="https://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2">Simple regular expression for a decimal with a precision of 2</a></p>
  
  <p>but none of them work for this use case</p>
  
  <p>What am I doing wrong?</p>