[英]Input mask jquery : letter or number
In jquery input mask , We can specify number and letter. 在jquery输入掩码中 ,我们可以指定数字和字母。 How to get the format where user can input letter or number,
如何获取用户可以输入字母或数字的格式,
A = Letter, 9 = number. A = Letter,9 =数字。
I need a mask like this AA - (A or 9)(A or 9) - 99
, 我需要一个像
AA - (A or 9)(A or 9) - 99
这样的面具AA - (A or 9)(A or 9) - 99
,
For example, it can be AA-99-99
例如,它可以是
AA-99-99
and in another case it can be AA-A9-99
, or 在另一种情况下,它可以是
AA-A9-99
,或
AA-AA-99
, AA-AA-99
,
and so on. 等等。 I have tried a lot, not suitable.
我尝试了很多,不适合。
Please advise. 请指教。
As you noted *
stands for alphanumeric character, so AA-**-99
should do the job. 如你所说
*
代表字母数字字符,所以AA-**-99
应该可以胜任。
Or you could use regexp lik [A-Za-z]{2}-\\w{2}-\\d{2}
, but it looks like regex placeholders like \\w
are not supported like this. 或者您可以使用regexp lik
[A-Za-z]{2}-\\w{2}-\\d{2}
,但看起来像\\w
这样的正则表达式占位符不支持。 Enclosing it to square brackets works ok: 将它括在方括号上可以正常工作:
<input id="example2" data-inputmask-regex="[A-Za-z]{2}-[\w]{2}-\d{2}" />
Here is a working plunker: https://plnkr.co/edit/SDkFm5VChO7W19VuOXmK?p=preview 这是一个工作的plunker: https ://plnkr.co/edit/SDkFm5VChO7W19VuOXmK ? p = preview
From the docs , you can use this method. 从文档中 ,您可以使用此方法。 The regex
AA-([A]|[9])([A]|[9])-99
will match your situation of numbers/letters. 正则表达式
AA-([A]|[9])([A]|[9])-99
将匹配您的数字/字母的情况。
HTML HTML
<input id="example2" data-inputmask-regex="AA-([A]|[9])([A]|[9])-99" />
Javascript 使用Javascript
(function() {
$("#example2").inputmask();
})();
如果用A表示字母A和9正好用数字9,那么这应该对你有用:
$("#myinput").inputmask({mask:"[AA]-[A|9]{2}-[99]"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.