Hello,


I have an input of type Number (bound to an integer variable) and I want to forbid the user to insert characters like ", . -", which appear on the mobile numeric keyboard. 

So, if the user presses these, I want to simply ignore them.

I have tried the onkeyup and onkeypress events to try to detect the key and if it was non-numeric, it would ignore it. 

The problem is that these two events are triggered when a numeric key is pressed, but not triggered otherwise. So, the non-numeric keys appear on the mobile keyboard, but there is no way to detect them using a Javascript event listener.

How can I detect these non-numeric characters and ignore them?


PS: I could detect these characters by changing the input type to Text, but then, the Text Mobile keyboard will appear, instead with the keyboard containing only numbers.


Thank you,

João Lopes

Hi João,

Did you try this component to restricted the characters.

Regards,

Marcelo

Hello,

If you still want to do it via javascript then I would bind it to onchange and just convert to integer using parseint().

Regards.

Marcelo Ferreira wrote:

Hi João,

Did you try this component to restricted the characters.

Regards,

Marcelo

Hello, 

I have tried it now but it didn't work. I inspected the code and it also uses the event listeners that I've used. Those do not catch the commas and dot characters.

Thank you for your help