RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

Regex failure #1927

Open HoecusPocus opened 6 years ago

HoecusPocus commented 6 years ago

Hi,

I have the entire bundle loaded, and after my page load I am calling this on a wrapped set:

numberOrPercentageInputs.inputmask({
        regex: "^(\\d+|\\d+[.]\\d+)%?$",
        rightAlign: true,
        showMaskOnHover: false,
        showMaskOnFocus: false,
        digitsOptional: true
});

I am basically trying to restrict the input to either a decimal or percentage. I used an online regex tester to ensure it works: regex

And I've escaped the slashes in this fiddle, but I get strange behaviour: fiddle

Is this a bug or am I using it incorrectly?

gvizquel commented 5 years ago

I have a similar problem. What I want is for the mask to only allow values ​​between 1 and 100. When I use version 3.x the mask works perfect. When trying to use version 4.x, the word "Regex" is displayed in the input. Here's the way I'm using it:

$(document).ready(function(){ $("#example1").inputmask('Regex', { regex: "^[1-9][0-9]?$|^100$" }); }); I tried changing the syntax to: $(document).ready(function(){ $("#example1").inputmask({ regex: "(^([1-9][0-9]$)|(^100$))" }); });

Now the input is always shown "^__$"

I ask the same question: is it a bug or am I using the library badly?

gvizquel commented 5 years ago

I could find this solution:

$(document).ready(function(){ $("#example1").inputmask({ regex: "^([0-9]|[1-9][0-9]|10[0])$" }); }); I really do not know if it's the right way to do it but it even works