How do I create a mask for a monetary value?
I'm using this:
$(".ValoresItens").inputmask('R$ 999.999.999,99', { numericInput: true});
It looks like this: R $
How do I create a mask for a monetary value?
I'm using this:
$(".ValoresItens").inputmask('R$ 999.999.999,99', { numericInput: true});
It looks like this: R $
If you are using the jquery.inputmask plugin, set the dynamic mask added to the thousands and decimal separator options, to remove the underlines change the placholder by zero.
<html>
<head>
<!-- não esqueça de adicionar os js do jquery e do pluging !-->
<script>
$(document).ready(function(){
$("#money").inputmask('decimal', {
'alias': 'numeric',
'groupSeparator': ',',
'autoGroup': true,
'digits': 2,
'radixPoint': ".",
'digitsOptional': false,
'allowMinus': false,
'prefix': 'R$ ',
'placeholder': ''
});
</script>
</head>
<body>
<form>
<input type="text" id="money" /><br>
</form>
</body>
</html>
Hello, mate. In your case I would recommend using the plugin Jquery Maskmoney , This pluginzinho already comes in the way to format fields for money according to your needs, plus some cool options. You can access the latest version of this plugin by clicking here
To format a field with this plugin according to what you are asking, use this:
$(document).ready(function()
{
$(".ValoresItens").maskMoney({
prefix: "R$:",
decimal: ",",
thousands: "."
});
});
In this way, your field will have the prefix R $: (quoted in the prefix option), the decimals will be separated by a comma (decimal option), and the thousands will be separated by a dot ( thousands option).
I just used this setting and it worked, this setting is for R $:
<html>
<head>
<!-- não esqueça de adicionar os js do jquery e do pluging !-->
<script>
$(document).ready(function(){
$("#money").inputmask( 'currency',{"autoUnmask": true,
radixPoint:",",
groupSeparator: ".",
allowMinus: false,
prefix: 'R$ ',
digits: 2,
digitsOptional: false,
rightAlign: true,
unmaskAsNumber: true
});
</script>
</head>
<body>
<form>
<input type="text" id="money" /><br>
</form>
</body>
</html>