Jquery Mask number with commas and decimal

James picture James · Feb 15, 2016 · Viewed 93.1k times · Source

I am using a Jquery mask plugin to format many things on my site and I am trying to figure out how to get it to format numbers in the way I need. I am using the following plugin.

https://igorescobar.github.io/jQuery-Mask-Plugin/

I am attempting to get the following format for my numbers.

999,999,999.99

The number is a currency field that needs a comma added every three digits and the value can be as low as 0.00

Answer

Phiter picture Phiter · Feb 15, 2016

Well, this worked. I just tweaked the example from the website changing dots with commas and it worked.

$('.money').mask("#,##0.00", {reverse: true});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.13.4/jquery.mask.min.js"></script>

<input class="money" type="text"/>    

As you can see there is no limitation of numbers. If you want to limit them, you can do $('.money').mask('000,000,000,000,000.00', {reverse: true});