-1

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?

isherwood
  • 58,414
  • 16
  • 114
  • 157
user1989
  • 47
  • 2
  • 7

3 Answers3

0

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

John Harper
  • 135
  • 1
  • 7
0

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

Brian Wiltshire
  • 447
  • 4
  • 15
0

Simply do this

<Input onPaste="return false" onCopy="return false" placeholder="Try to copy or paste here" />
GMKHussain
  • 3,342
  • 1
  • 21
  • 19