0

Is there any way to disable copy/paste of specific control on HTML input field ? I found way to disable c/p with preventDefault(), but i need to disable c/p of specific control ?

EDIT:

Or how to restrict specific key to enter on input field? (e.g. TAB key)

soja4
  • 41
  • 1
  • 2
  • 4
  • 4
    Possible duplicate of [Disable copy paste in HTML input fields?](http://stackoverflow.com/questions/12805803/disable-copy-paste-in-html-input-fields) – George Mar 20 '17 at 10:18
  • Possible duplicate of [Disable pasting text into HTML form](http://stackoverflow.com/questions/1226574/disable-pasting-text-into-html-form) – Anthony Granger Mar 20 '17 at 10:40
  • On input change you can remove disallowed input just by replacing them with nothing something like `in = in.replace('\t', '')` where `in` is the text. – Nick is tired Mar 20 '17 at 10:45

1 Answers1

0

Your Html code

<input type="text" value="" id="myInput" />

Your js code.

  window.onload = function() {
                        var myInput = document.getElementById('myInput');
                     myInput.onpaste = function(e) {
                 e.preventDefault();
                }
            }
Iqbal Butt
  • 196
  • 2
  • 15