Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Mask number with commas and decimal

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

like image 265
James Avatar asked Feb 15 '16 15:02

James


2 Answers

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});

like image 114
Phiter Avatar answered Nov 16 '22 20:11

Phiter


Try this mask from their website with inverting commas and dots:

$('.money').mask('000.000.000.000.000,00', {reverse: true});

to have

$('.money').mask('000,000,000,000,000.00', {reverse: true});
like image 33
ADreNaLiNe-DJ Avatar answered Nov 16 '22 20:11

ADreNaLiNe-DJ