Do I need to lock ctrl + v in a text box

I want to create an input type="text" that does not allow them to paste anything into it. You don't need to present any alert or anything like that, just don't allow the paste.

 9
Author: paulomartinhago, 2014-02-27

4 answers

If you are using jQuery in your application, you can do as follows:

In your HTML

<input type="text" id="texto"></input>

In your Javascript

$(document).ready(function() {

    $("#texto").bind('paste', function(e) {
        e.preventDefault();
    });

});

If you need examples of how to detect copy and clipping of text, this post has nice examples:

Http://www.mkyong.com/jquery/how-to-detect-copy-paste-and-cut-behavior-with-jquery/

 17
Author: Madureira, 2014-02-27 01:18:13

Just to add an alternative the options mentioned above:

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

The onpaste attribute picks up the paste event and the ondrop drag event. In this way, the user will be prevented from both pasting text (ctrl+v or right mouse button) and dragging text with the mouse into this field.

 7
Author: Diego Magdaleno, 2015-07-17 17:41:06

To avoid Crtl+C Crtl + V or Crtl + X, you can use that as well...

 $(document).ready(function() {
     $('#texto').bind('cut copy paste', function(event) {
         event.preventDefault();
     }); 
 });
 3
Author: alexandrenascimento, 2014-02-27 18:07:43

If pure javascript, this template inline serves:

document.getElementById('texto').onpaste = function(){
    return false;
}

If you don't want to use inline mode, you can do this (IE > 9):

document.getElementById('texto').addEventListener(
    'paste', 
    function(E){
        E.preventDefault();
        return false;
    },
    true
);

In this mode, if you need to include IE below version 10, you need to condition the expressions using attachEvent for IE and addEventListener for the rest of the browsers.

Good luck.

 3
Author: , 2014-03-01 15:26:06