title: Format numbers on input
body: <p>I have been looking around and can't seem to find an way to do this. As a user inputs a number into a input field e.g:</p>
  
  <pre><code>&lt;input type="text" class="numberOnly" id="miles" value="" /&gt;
  </code></pre>
  
  <p>How can I get that to update as they are typing to something like. e.g:</p>
  
  <p>Input: 100000</p>
  
  <p>Output: 100,000</p>
  
  <p>I have some similar code that formats some other things as I calculate them, here is the function I'm using to format my other numbers.</p>
  
  <pre><code>function format_num(number) {
          number += '';
          x = number.split('.');
          x1 = x[0];
          x2 = x.length &gt; 1 ? '.' + x[1] : '';
          var rgx = /(\d+)(\d{3})/;
          while (rgx.test(x1)) {
              x1 = x1.replace(rgx, '$1' + ',' + '$2');
          }
          return x1 + x2;
      }
  </code></pre>
  
  <p>This works fine, like I said I'm not sure how to put the users input value into this and get the output back into the input field while they are typing. </p>
  
  <p>Note: I need to format more then 1 input field.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I have this in my code that will trigger each time the keyboard is pressed, so that can be used. This is used for the whole form so the form updates each time a button is pressed.</p>
  
  <pre><code> $(".numberOnly").keypress(function (e) {
              //if the letter is not digit then display error and don't type anything
              if (e.which != 8 &amp;&amp; e.which != 46 &amp;&amp; e.which != 0 &amp;&amp; (e.which &lt; 48 || e.which &gt; 57)) {
                  //display error message
                  $("#errmsg").html("Digits Only").show().fadeOut(1600);
                  return false;
              } else {
                  $('input').keyup(function () {
  
  
  
                  });
              }
          });
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>Is it possible to make an kind of overlay for it, e.g: the value of the input is 1000 but the overlay shows it to the use as 1,000?</p>
  
  <p>Any help would be great guys. 
  Many thanks!</p>