3
People I have the following function that I am using to use Coin mask
<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>
Only that I wanted to implement in this function . Currency as follows: When I enter only one number (e.g.: 1) it returns "R$ 1,00" (currently returns "R$ 1") and when I enter 2 numbers (e.g.: 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"; type "1111" > "R$ 11.11").
Ah, if you have a different function (that serves the same way), you can send it, but please send some example online to test via input (other than by "Alert" or "console", commands this same scheme that I sent) because I do not know how to call the function in other molds (type "Function (number) {...")
Man, I don’t know how to use it there (I tried and I couldn’t) :/ Send an example with equal input is in mine currently, then you send with the changes
– Thyago Barbosa