title: Add space separator to number in input box
body: <p>I'm trying to get an input box to display numbers with space separator. Like this:
  20 000 and 20 000 000 instead of 20000 and 20 000 000</p>
  
  <p>The thing is that I want this to happen as you type. So when you type a number into an input element I want this spacing to be added on the fly.</p>
  
  <p>Does anyone have a good solution for this?</p>
  
  <p>I'm using this function to do this on static outputs, but it doesn't work well when getting the value from a textbox,  running it through the function and then putting it back, for some reason.</p>
  
  <pre><code>function delimitNumber(number) {
      var delimiter = " "; 
  
      number = new String(number);
      var parts = number.split('.', 2);
      var decimal = parts[1];
      var i = parseInt(parts[0]);
  
      if(isNaN(i)) 
          return ''; 
  
      var minus = '';
  
      if (i &lt; 0) 
          minus = '-'; 
  
      i = Math.abs(i);
      var n = new String(i);
      var a = [];
  
      while(n.length &gt; 3) {
          var nn = n.substr(n.length-3);
          a.unshift(nn);
          n = n.substr(0,n.length-3);
      }
  
      if (n.length &gt; 0) 
          a.unshift(n); 
  
      n = a.join(delimiter);
  
      if (typeof decimal === 'undefined' || decimal.length &lt; 1)  
          number = n;
      else 
       number = n + '.' + decimal;
  
      number = minus + number; // Assemble the number with negative sign (empty if positive)
      return number;
  }
  </code></pre>