How to block +,-,e in input type Number?

后端 未结 13 1776
我在风中等你
我在风中等你 2020-12-29 20:52

When I\'m giving input type number the letter e and special charecters are also displaying in input field. I want to display only digits. How to block them?

13条回答
  •  礼貌的吻别
    2020-12-29 21:31

    You can do it easily using jQuery

    Try this code

    $(function() {
        $("#input").keypress(function(event) {
            if (event.which != 8 && event.which != 0 && (event.which < 48 || event.which > 57)) {
                $(".alert").html("Enter only digits!").show().fadeOut(2000);
                return false;
            }
        });
    });
    
    
    

提交回复
热议问题