title: Adding space between numbers
body: <p>I'm trying to make a number input. I've made so my textbox only accepts numbers via this code:</p>
  
  <pre><code>function isNumber(evt) {
      evt = (evt) ? evt : window.event;
      var charCode = (evt.which) ? evt.which : evt.keyCode;
      if (charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) {
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>But now the question comes to, how would I create spaces as the user is typing in their number, much like the iPhone's telephone spacing thing, but with numbers so for example if they type in: 1000 it will become 1 000;</p>
  
  <pre><code>1
  10
  100
  1 000
  10 000
  100 000
  1 000 000
  10 000 000
  100 000 000
  1 000 000 000
  </code></pre>
  
  <p>Etc...</p>
  
  <p>I've tried to read the input from the right for each 3 characters and add a space. But my way is inefficient and when I'm changing the value from 1000 to 1 000 in the textbox, it selects it for some reason, making any key press after that, erase the whole thing.</p>
  
  <p>If you know how to do this, please refrain from using javascript plugins like jQuery. Thank You.</p>