Currency Mask with jquery

Asked

Viewed 3,901 times

0

I need a tag for a value field, I’m using jquery.maskinput works perfect but I have to enter the entire value!

what I’m looking for is a mask that fills automatic " R$ var.000,00 "

for example, if I have a value of 500mil , with maskinput I would type

50000000

but with the mask I quoted above I would only have to type

500

someone has some hint about this??

2 answers

2

Without doing any validation, just to get what you quoted.

$('input').on('keyup', function() {

var v = $(this).val();

if (parseInt(v.length) === 3) {

$(this).val((v * 1000).toLocaleString('pt-br', {style: 'currency', currency: 'BRL'}));

}

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" />

  • I appreciate the quick response, so the values of this input vary a lot, between 50mil and 4milhoes , so it would have to be a type of mask where it accompanies the value, what you passed worked but only with values between 100mil to 999mil

0

  • I tried to use maskmaney but I could not edit to leave as I want :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.