title: Adding commas to numbers when typing
body: <p>I am trying to add commas when the user type a number. What is the correct syntax to select the <code>input form-control</code> class with attribute <code>number</code> type in Jquery?</p>
  <p>EDIT: I can't change the HTML code since it is outputted from Django with Bootstrap.</p>
  <p><strong>HTML</strong></p>
  <pre><code>&lt;span class=&quot;input-group-addon&quot;&gt;$&lt;/span&gt;
  &lt;input class=&quot;form-control&quot; id=&quot;id_step2-number_2&quot;
         name=&quot;step2-number_2&quot; type=&quot;number&quot;&gt;
  &lt;span class=&quot;input-group-addon&quot;&gt;.00&lt;/span&gt;
  </code></pre>
  <p><strong>JQuery</strong></p>
  <pre><code>$(document).ready(function(){
      $(&quot;input[type='number']&quot;).keyup(function(event){
          // skip for arrow keys
          if(event.which &gt;= 37 &amp;&amp; event.which &lt;= 40){
              event.preventDefault();
          }
          var $this = $(this);
          var num = $this.val().replace(/,/gi, &quot;&quot;)
              .split(&quot;&quot;).reverse().join(&quot;&quot;);
            
          var num2 = RemoveRougeChar(
              num.replace(/(.{3})/g,&quot;$1,&quot;).split(&quot;&quot;)
                  .reverse().join(&quot;&quot;)
          );
            
          console.log(num2);
  
          // the following line has been simplified.
          // Revision history contains original.
          $this.val(num2);
      });
  });
      
  function RemoveRougeChar(convertString){
      if(convertString.substring(0,1) == &quot;,&quot;){
          return convertString.substring(1, convertString.length)            
      }
      return convertString;
  }
  </code></pre>
  <p><strong>JSFiddle Link</strong>
  <a href="https://jsfiddle.net/yWTLk/767/" rel="nofollow noreferrer">https://jsfiddle.net/yWTLk/767/</a></p>