title: Thousand separator in numeric input with jQuery and regularexpressions
body: <p>I need to make my numeric input in such mode: {1-3 numbers} {white-space} {3 numbers} {white-space} {3 numbers} {white-space} .. and so on..</p>
  
  <p>For example, when user enters 1000 it should be converted to 1 000, than he enters 1 0000, and it will be converted to 10 000; on deleting last zero input value should return to 1 000</p>
  
  <p>there's a <strong>jquery plugin autonumeric</strong>, but i need only this thousand separating function</p>
  
  <p>my code looks like:</p>
  
  <pre><code>$('#myinput').live('keypress', function() {
      if ($(this).val().length == 3){
          newval = $(this).val().replace(/([0-9])([0-9]{2}$)/, '$1 $2');
      }
      if ($(this).val().length == 4){
          newval = $(this).val().replace(/([0-9])([0-9]{3}$)/, '$1 $2');
      }
      ...
      $(this).val(newval);
  });
  </code></pre>
  
  <p>it doesn't work properly, as well as this:</p>
  
  <pre><code>newval  = $(this).val().replace(/(\S{1,3})([$0-9]{2})/g, '$1 $2');
  newval2 = newval.replace(/([0-9]{1})[\s]([0-9]{1})[\s]/g, '$1$2 ');
  </code></pre>
  
  <p>this one fails on deleting last number</p>