Search code examples
javascriptjqueryinputmasking

Input Masking for indian currency In Jquery dyanamic Input field


I want show masking as per the Indian currency while writing in input box.

I am using InputMask jquery for masking : https://github.com/RobinHerbots/Inputmask

I want that wherever users tries to write down amount in Text Input then it should add automatic comma as per the Indian Currency format.

I am trying to achieve that by using following code.

<input type="text" name="amount" class="amount_field"/>
$('.amount_field').inputmask("numeric", {
            radixPoint: ".",
            groupSeparator: ",",
            digits: 3,
            autoGroup: true,
            prefix: '',
            rightAlign: false,
            allowMinus: false,
            // oncleared: function () { self.Value(''); }
        });

Current Output: 2,500,000

Needed Output : 25,00,000

As per the Indian currency I needed coma first after 3 and then by 2.

Any help will be apprciated.


Solution

  • I have implement your issue with simple following you can try that.

    Note: In latest version of InputMask Indian Currency style has been added. Check latest release here. : https://github.com/RobinHerbots/Inputmask/commit/5586f25853e96102417888b2cfc2823f3caa9763

    <input type="text" class="inputmasking" value=""/>
    <input type="text" class="inputmasking" value=""/>
    <input type="text" class="inputmasking" value=""/>
    
    <script type="text/javascript">
    Inputmask("(,99){*|1}(,999){1|1}",
         {
             positionCaretOnClick: "radixFocus",
             _radixDance: true,
             radixPoint: ".",
             numericInput: true,
             placeholder: "0"
         }
     ).mask(".inputmasking");
    </script>
    

    enter image description here

    Working example of fiddle : https://jsfiddle.net/mayanksdudakiya/58pnxjvw/