Jquery input.mask with regex

agriboz picture agriboz · Dec 23, 2014 · Viewed 38.7k times · Source

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:

99:59:59

Fiddle

Answer

Buster picture Buster · Dec 23, 2014

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.

edit: changed '-' to ':'