简体   繁体   中英

Input mask jquery : letter or number

In jquery input mask , We can specify number and letter. How to get the format where user can input letter or number,

A = Letter, 9 = number.

I need a mask like this AA - (A or 9)(A or 9) - 99 ,

For example, it can be AA-99-99

and in another case it can be AA-A9-99 , or

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.

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. 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

From the docs , you can use this method. The regex AA-([A]|[9])([A]|[9])-99 will match your situation of numbers/letters.

HTML

<input id="example2" data-inputmask-regex="AA-([A]|[9])([A]|[9])-99" />

Javascript

(function() {

    $("#example2").inputmask();

})();

如果用A表示字母A和9正好用数字9,那么这应该对你有用:

$("#myinput").inputmask({mask:"[AA]-[A|9]{2}-[99]"});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM