How to prevent user pasting text in a textbox?

后端 未结 5 781
我寻月下人不归
我寻月下人不归 2020-12-14 16:42

I have this JS function that prevents user from typing characters



        
5条回答
  •  难免孤独
    2020-12-14 17:31

    I tried this in my Angular project and it worked fine without jQuery.

    
    

    And in script part:

    $scope.preventPaste = function(e){
       e.preventDefault();
       return false;
    };
    

    In non angular project, use 'onPaste' instead of 'ng-paste' and 'event' instead of '$event'.

提交回复
热议问题