jrobinsonc
10/1/2013 - 4:29 PM

Only numbers Allow only numeric (0-9) in HTML input using jQuery.

Only numbers Allow only numeric (0-9) in HTML input using jQuery.

$('input[type=number]').on('keydown', function(evt) {
    var key = evt.charCode || evt.keyCode || 0;

    return (key == 8 ||
            key == 9 ||
            key == 46 ||
            key == 110 ||
            key == 190 ||
            (key >= 35 && key <= 40) ||
            (key >= 48 && key <= 57) ||
            (key >= 96 && key <= 105));
});