Add commas for a number in input field while typing
<p>This does it incorrectly:
<a href="http://stackoverflow.com/questions/2632359/can-jquery-add-commas-while-user-typing-numbers">Can jQuery add commas while user typing numbers?</a></p>

<pre><code>  $('input.number').keypress(function(event){
      if(event.which &gt;= 37 &amp;&amp; event.which &lt;= 40){
          event.preventDefault();
      }
      var $this = $(this);
      var num = $this.val().replace(/,/g, '');
      $this.val(num.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
  });
</code></pre>

<p>I need "1000000" to be "1,000,000" or better with spaces "1 000 000".</p>

<p>Please help. Thanks.</p>
