Search code examples
javascriptjqueryjquery-mask

Set specific digit range jquery.mask


I need the first digit to be from [1-9], which would omit the 0. So i tried something like

$("#myid").mask("[1-9]999999999"); 

Is there a specific work out for mask library?

Thanks in advance.


Solution

  • In the source code we have:

    $.mask = {
        //Predefined character definitions
        definitions: {
            '9': "[0-9]",
            'a': "[A-Za-z]",
            '*': "[A-Za-z0-9]"
        },
        autoclear: true,
        dataName: "rawMaskFn",
        placeholder: '_'
    };
    

    So, stick this line somewhere after you've loaded the library:

    $.mask.definitions['1'] = "[1-9]";
    

    Then this should work (jsfiddle):

    $("#myid").mask("1999999999");