Skip to content
Advertisement

How to restrict strings in html input type text without setting type to number

I have this line of html code.

JavaScript

I want it to accept only numbers.The reason I used type as text, is that I also want to use the minlength and maxlength attributes. How do I achieve this? Alternatively, how can I use input type number, and have the minlength and maxlength working?

Advertisement

Answer

You have to set a JS event handler on the change event of that input.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement