最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - inputmask numeric with two decimal places - Stack Overflow

programmeradmin1浏览0评论

I'm trying to transform my normal input field unto a numeric input with two decimal places using the great plugin called "inputmask" by awesome "RobinHerbots", below snippet is what I tried but sadly and unfortunately its not working, any ideas, help please?

$(document).ready(function(){
  $('.decimal').inputmask('decimal', { rightAlign: false, digits: 2, placeholder: "0" });
});
<script src=".1.1/jquery.min.js"></script>
<script src=".inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<input type="text" class="decimal form-control" />

I'm trying to transform my normal input field unto a numeric input with two decimal places using the great plugin called "inputmask" by awesome "RobinHerbots", below snippet is what I tried but sadly and unfortunately its not working, any ideas, help please?

$(document).ready(function(){
  $('.decimal').inputmask('decimal', { rightAlign: false, digits: 2, placeholder: "0" });
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit./RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<input type="text" class="decimal form-control" />

Share Improve this question edited Nov 27, 2015 at 4:11 Juliver Galleto asked Nov 27, 2015 at 3:49 Juliver GalletoJuliver Galleto 9,05727 gold badges92 silver badges169 bronze badges 3
  • 2 i just played around with it i dont know if this will help but give it a look $('.decimal').inputmask({ mask: "*[.**]", greedy: false, definitions: { '*': { validator: "[0-9]" } } }); – guradio Commented Nov 27, 2015 at 4:32
  • @guradio: cool, but how to extend the digits, currently its like "6.55" and I want like this "6.555555555 and so on" any ideas? – Juliver Galleto Commented Nov 27, 2015 at 6:20
  • were you able to make it?i cant a way to make many decimals you can increase *** to achieve what you want but i think it is not a good idea you need a dynamic approach on that which i havent got any solution to – guradio Commented Nov 28, 2015 at 4:19
Add a ment  | 

2 Answers 2

Reset to default 2
$('.decimal').inputmask({ mask: "99.99"}) // As you requested

OR

$('.decimal').inputmask({ mask: "99.9{2}"}) //Same as the first one, {2} mean preceding char count MUST be 2

OR

$('.decimal').inputmask({ mask: "(99)|(99.9{1,2})"}) //We use optional here so user can enter 99 or 99.9 or 99.99

Try this

https://jsfiddle/Ln375fmz/

$('.decimal').inputmask({
            mask: "9{0,20}Z9{2}",
            definitions: {
                "Z": {
                    validator: "[.]",
                }
            },
            clearInplete: true,
            autoUnmask: true,
            placeholder: "",
        });
<input type="text" id="money">

发布评论

评论列表(0)

  1. 暂无评论