Mask for monetary values

Asked

Viewed 1,510 times

4

I wanted to create a mask for monetary values, where the person would type and enter the scores and separations of the decimals automatically. Ex:

R$ 1

R$ ,11

R$ 1,10

R$ 11,00

R$ 110,00

R$ 1,110,00

and so on

I tried using jQuery.Inputmask from Nuget, but it only serves to use a full mask

  • Tried Jquery-maskMoney?

1 answer

8


There are several plugins (list of mask plugins for jQuery). For your requirements the jquery-maskMoney seems to be ideal:

$("#meuDinheiro").maskMoney();
<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-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>



<input type="text" id="meuDinheiro" data-thousands="." data-decimal="," data-prefix="R$ " />

  • Thank you, that’s what I was looking for :)

  • I applied the function in my code today, but I’m using Asp.net-mvc’s Editorfor and the data from data-thousands="." date-decimal="," date-prefix="R$ " are not recognized, how could you do? This is the code line: @Html.Editorfor(model => model. Salario, new { htmlAttributes = new { @class = "form-control",id="meudinheiro" } })

  • for input type works, but using Editorfor does not

  • Already solved here... on the link you left, has the format... Thanks

Browser other questions tagged

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