Jquery input.mask with regex

48.4k Views Asked by At

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

3

There are 3 best solutions below

0
On BEST ANSWER

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 ':'

1
On

You mean something like this:

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

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