最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Input mask jquery : letter or number - Stack Overflow

matteradmin2PV0评论

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.

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.

Share Improve this question edited Oct 24, 2017 at 13:49 Gabriel Mesquita 2,4111 gold badge23 silver badges30 bronze badges asked Oct 24, 2017 at 13:37 Fadly DzilFadly Dzil 2,2365 gold badges42 silver badges93 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4

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();

})();

If by A you mean exactly the letter A and by 9 exactly the number 9, then this should work for you:

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

comment list (0)

  1. No comments so far