Allow only numeric value in textbox using Javascript

前端 未结 9 1073
礼貌的吻别
礼貌的吻别 2020-12-19 21:52

I want to allow only numeric values to be entered into the text and if user enters alphabetic character it should warn the user. Any suggestion for optimized and short javas

9条回答
  •  误落风尘
    2020-12-19 21:58

    @Shane, you could code break anytime, any user could press and hold any text key like (hhhhhhhhh) and your could should allow to leave that value intact.

    For safer side, use this:

    $("#testInput").keypress(function(event){
    

    instead of:

    $("#testInput").keyup(function(event){
    

    I hope this will help for someone.

提交回复
热议问题