简体   繁体   中英

Disable copy paste in textbox

I have my input Textbox like below. User should not be allowed to perform copy paste in the Textbox. But somehow my code is not working. Is there any other approach?

<input type="text" class="form-control"  id="startTextbox1" appOnlynumber onkeypress='validate(event)' onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false" formControlName="startTextbox1">

I have also written custom directive like it specified in below link but its not working.

https://stackblitz.com/edit/angular-u4jcam?file=app%2Fapp.component.html

Any suggestions please?

Not sure this is what you are going for, but perhaps this prior question gives you some place to start:

Disable pasting text into HTML form

I know you can do this with JS / jQuery

$(document).ready(function(){
   $('#startTextbox1').on("cut copy paste",function(e) {
      e.preventDefault();
   });
});

Hope that can help

Simply do this

 <Input onPaste="return false" onCopy="return false" placeholder="Try to copy or paste here" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM