Change the currency symbol or delete it in the currency of the input mask

I am using Robin Herbot inputmask jquery plugin and I want to change the default currency symbol (by default it is the dollar currency symbol) to the PESO currency symbol or delete the currency symbol.

Below I tried, yes, the character changes, and the character is deleted, but it does not allow me to enter anything.

$(document).ready(function(){ $("#currency1").inputmask({ alias : "currency", mask : "0.00" }); $("#currency2").inputmask({ alias : "currency", mask : "₱ 0.00" }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" /><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" /> 
+5
source share
2 answers

You can change the character using the prefix option. Below is a snippet where I do this in two different ways, changing the currency alias and defining my own alias.

In your version you cannot enter anything, because the mask property is used to limit input and set it to 0.00 can only enter these four characters and nothing more. The 9.99 mask will allow a number followed by a period and two numbers. 9 has a special definition of disguise that allows any number.

 Inputmask.extendAliases({ pesos: { prefix: "₱ ", groupSeparator: ".", alias: "numeric", placeholder: "0", autoGroup: !0, digits: 2, digitsOptional: !1, clearMaskOnLostFocus: !1 } }); $(document).ready(function(){ $("#currency1").inputmask({ alias : "currency", prefix: '' }); $("#currency2").inputmask({ alias : "currency", prefix: '₱ ' }); $("#currency3").inputmask({ alias : "pesos" }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" /><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" /><br> <label>CHANGE THE CURRENCY SYMBOL, using an alias</label><br> <input type="text" id="currency3" /> 
+3
source

Solution with data-inputmask attribute

 $(document).ready(function(){ $("input").inputmask(); }); 
 <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.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" data-inputmask="'alias': 'decimal', 'groupSeparator': ',', 'autoGroup': true, 'digits': 2, 'digitsOptional': false, 'placeholder': '0'" style="text-align: right;"><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" data-inputmask="'alias': 'decimal', 'groupSeparator': ',', 'autoGroup': true, 'digits': 2, 'digitsOptional': false, 'prefix': '₱ ', 'placeholder': '0'" style="text-align: right;"> 
+1
source

Source: https://habr.com/ru/post/1241467/


All Articles