Restrict input to number only on pasting

后端 未结 7 784
佛祖请我去吃肉
佛祖请我去吃肉 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:40

    Actually it must be like that for jquery;

    $('.just_numbers').on('paste keyup', function(e){ $(this).val($(this).val().replace(/[^\d]/g, '')); });

    Paste also, pressing also ignoring except numbers.

提交回复
热议问题