javascriptjqueryfrontendinput-maskjquery-inputmask

How do I set the range in the Inputmask plugin?


I use Inputmask

I need a mask from 10 to 120

To do this, this mask must be written somehow for a certain input

Tell me please, knowledgeable people

test-1 works, but in js for test-2 you need to add something, but what I don't understand what exactly

HTML

<div id="test-1" mask-val="9-ZZ-9">
  test-1 <input type="text" />
</div>
<br>
<div id="test-2" inputmask-alias="from10to120">
  test-2 <input type="text" />
</div>

JS

let mask_1 = $("#test-1")[0].getAttribute("mask-val");
Inputmask(mask_1).definitions.Z = {
  validator: "[A-Za-z]",
  casing: "upper"
};
Inputmask(mask_1).mask($("#test-1>input")[0]);

let mask_2 = $("#test-2")[0].getAttribute("inputmask-alias");
Inputmask(mask_2).extendAliases = {
  from10to120: {
    mask: "^(\d{2}|10[0-9]|11[0-9]|120)$",
    placeholder: ""
  }
};
Inputmask(mask_2).mask($("#test-2>input")[0]);

code in codepen


Solution

  • You can try this one :

    $("#test-2>input").inputmask('numeric', { 
      min: 10,
      max: 120,
      allowMinus: false,
      digits: 0
    });
    

    Here is an exemple in Codepen : https://codepen.io/AZIIZoom/pen/rNmPWbN