Gaspa79 Gaspa79 - 2 years ago 62
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!

Answer Source

The definite answer is this:

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

            if (key == 46) {

And bind it on keypress

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download