1

I am trying to use Jquery Mask

Html:

<script src="~/Content/jquery.mask.js"></script>

<input id="test1" type="text" data-mask-maxlength="false" />

Javascript/Jquery:

$("#test1").mask('000.000.000.000.000.000.000', { reverse: true });

I tried below

 function RemoveRougeChar(convertString) {
            if (convertString.substring(0, 1) == ",") {
                return convertString.substring(1, convertString.length)
            }
            return convertString;
        }

        $("#test1").on("focus", function (e) {
            var $this = $(this);
            var num = $this.val().replace(/,/g, "");
            $this.val(num);

        }).on("blur", function (e) {
            var $this = $(this);
            var num = $this.val().replace(/[^0-9]+/g, '').replace(/,/gi, "").split("").reverse().join("");
            var num2 = RemoveRougeChar(num.replace(/(.{3})/g, "$1,").split("").reverse().join(""));
            $this.val(num2);
        });

Question:

I have value as below,

1

10

100

100.000

1.000.000

If user add comma last of value as below

1,00

10,0

100,00

100.000,0

1.000.000,00

User only add 1 or 2 numbers more after comma after last number like above values.

How can i provide this by using jquery mask

Richard
  • 137
  • 1
  • 1
  • 12

0 Answers0