-1
I would like to know if there is any way to use masks for money without having to jQuery
. I know the toLocaleString
to format, but would like to apply a mask in the field. I searched the internet but unsuccessfully.
I have a input
and would like to apply the value of toLocaleString
on it. At the moment I only catch it with.
let salario = document.querySelector('#contract_salary');
salario.addEventListener('keyup', () => {
console.log(salario.value.toLocaleString("pt-BR", { minimumFractionDigits:2, style: 'currency', currency: 'BRL' }))
})
<input type="text" class="form-control" id="contract_salary" name="contract_salary" required>
This one is more interesting https://answall.com/questions/181922/formatter-brasileira-em-javascript
– Leandro Angelo
There is no way to make mask with
.toLocaleString
by typing because it formats the value as a whole and not in pieces.– Sam
It has a lib called jquery Mask, very good.
– Daniel Aloísio
Have you tried Simplemaskmoney https://www.npmjs.com/simple-mask-money
– Augusto Vasques