title: How can I format currency by using JQuery
body: <p>I am trying to format currency by using this code below:</p>
  
  <pre><code>$('#currency').keyup(function(e){
     var val = $(this).val();
     val = val.replace(/[^0-9]/g,'');
     if(val.length &gt;= 2)
     val = '$' + val.substring(0,2) + ',' + val.substring(2);
     if(val.length &gt;= 6)
     val = val.substring(0,7) + val.substring(7);
     if(val.length &gt; 7)
     val = val.substring(0,7); 
     $(this).val(val);
   });  
  </code></pre>
  
  <p>But that would work only for volume such as "$10,000" or something like that, How can I include thousands, hundreds, and millions in one code? </p>