Javascript 带有正则表达式的 Jquery input.mask
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27616739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery input.mask with regex
提问by agriboz
I want to implement simple jquery mask pluging using jquery input.mask plugin, however, i cannot make it work with regex. What i want to achieve is:
我想使用jquery input.mask plugin实现简单的 jquery 掩码插件,但是,我无法使用正则表达式。我想要实现的是:
99:59:59
回答by Buster
You can do it like this.
你可以这样做。
$("#test").inputmask({
mask: "99:59:59",
definitions: {'5': {validator: "[0-5]"}}
});
The validator is an expression. Telling the "5" in the mask string to contain only numerical characters from 0 to 5.
验证器是一个表达式。告诉掩码字符串中的“5”只包含从 0 到 5 的数字字符。
edit: changed '-' to ':'
编辑:将“-”更改为“:”
回答by Ferret
回答by Arun Prasad E S
use
用
<script src="../js/jquery.inputmask.bundle.js"></script>
<asp:TextBox class="form-control" ID="trvl_amt" data-inputmask="'mask': '9{0,50}.9{0,2}'" data-mask placeholder="Travel Amount" runat="server"></asp:TextBox>
Up to 50 numeric places + 2 Decimal
最多 50 个数字位 + 2 个小数

