Restrict input to number only on pasting

后端 未结 7 785
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 21:54

I have an input filed with a class called restrict-numbers which i want to restrict the entered characters to only accept numbers, i used the following code which is great b

相关标签:
7条回答
  • 2021-01-18 22:53

    This code is for javascript and used in my angular app.

    jQuery('#Id').on('paste keyup', function(e){
        jQuery(this).val(document.getElementById('Id').value.replace(/[^\d]/g, ''));
      });
    

    Where Id is input field id and it is blocked alphabet to enter and paste in the field.

    0 讨论(0)
提交回复
热议问题