Detect paste in input box

Use the onpaste event to capture the event and do what you need in Javascript. E.g. to disable the paste in an input text field:

<input type="text" onpaste="return false;" />

Javascript supports onpaste:

http://www.quirksmode.org/dom/events/cutcopypaste.html


Just for future readers finding this as I did.

You will still be able to drop text into an input with the onpaste="return false;" attribute. If you want to avoid this, you can do something like this:

var input_element = document.getElementById("Element");
input_element.addEventListener("drop", function (event) {
    var types = event.dataTransfer.types;
    
    if (types.length > 2 || types.indexOf("text/plain") === -1)
        event.preventDefault();
    else {
      setTimeout(function () { input_element.value = ""; }, 10);
    }
}, false);