Gaspa79 Gaspa79 - 4 months ago 6x
HTML Question

Don't let a user type the period character in an HTML5 input type number

So right now the user is able to insert a decimal value in the number field of the HTML5 input type="number". I want to prevent that, so if a user types "5.1" it will insert "51" in the textbox.

Is there any way to do this? Thanks!


The definite answer is this:

function preventDot(e) {
            var key = e.charCode ? e.charCode : e.keyCode;

            if (key == 46) {

And bind it on keypress