Home > Back-end >  Prevent letters from input is not working how I want
Prevent letters from input is not working how I want

Time:06-30

I have the following code: https://codepen.io/ion-ciorba/pen/MWVWpmR

The problem is on "Suma solicitata" value, there you can click and edit the value, but when trying to replace a number inside the whole one, the newly replaced number will go to the end of it. How can I fix this, I think it's because of that:

var preventOnlyLetters = function (event) {
                    $(this).val($(this).val().replace(/[^\d] /, ""));
}

CodePudding user response:

It's happening because you are triggering this function both on keypress and keyup. You should only have it on either keyup or keypress. But I think it would be much better if you just make the input type="number"

  • Related