People I have the following function that I am using to use Currency masks
<input class="valr-parc" type="text" name="valr-parc" />
<script>
String.prototype.Moeda = function() {
var v = this;
v = v.replace(/\D/g,'')
v = v.replace(/(\d{1})(\d{1,2})$/, "$1,$2")
v = v.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')
v = v.replace(/^(\d)/g,"R$ $1")
return v;
}
</script>
<script type="text/javascript">
(function(view) {
var valr_parc = document.getElementsByClassName("valr-parc")[0];
valr_parc.onkeyup = function(){
this.value = this.value.Moeda();
};
})(this);
</script>
I just wanted to implement this function. Moove the following: When I type only a number (ex: 1) it returns "$ 1.00" (currently returns "$ 1") and when I enter 2 numbers (ex: 11) it returns "R $ 1,10" (currently returns "R $ 1.1) hence from these two conditions it can already start to run the way it is (ex: if you type" 111 "returns" R $ 1.11 ", enter" 1111 ">" R $ 11.11 ").
Ah, if you have a different function (that works the same way), you can send it, but please send some example online to test via input (not by "alert" or "console" I did not know how to call the function in other templates (type "function (numero) {...")