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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:24:07  来源:igfitidea点击:

Jquery input.mask with regex

javascriptjqueryinputjquery-inputmask

提问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

Fiddle

小提琴

回答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

You mean something like this:

你的意思是像这样

$('#test').inputmask('Regex', { 
    regex: "^[0-9]{2}:[0-5][0-9]:[0-5][0-9]$"
});

回答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 个小数