Allow only numeric value in textbox using Javascript

前端 未结 9 1063
礼貌的吻别
礼貌的吻别 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:57

    // Solution to enter only numeric value in text box

    $('#num_of_emp').keyup(function () { 
        this.value = this.value.replace(/[^0-9.]/g,'');
    });
    

    for an input box such as :

提交回复
热议问题