I want to create an input type="text"
that does not allow anything to be pasted into it. You do not need to have any alert
or anything, just do not allow the paste.
I want to create an input type="text"
that does not allow anything to be pasted into it. You do not need to have any alert
or anything, just do not allow the paste.
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 some cool examples:
>Just to add an alternative to the options mentioned above:
<input type="text" onpaste="return false" ondrop="return false"/>
The onpaste
attribute takes the paste event and the ondrop
drag. This way, the user will be prevented either from pasting text (ctrl + v or right mouse button) or dragging text with the mouse into that field.
To avoid Crtl + C Crtl + V or Crtl + X, you can use it as well ...
$(document).ready(function() {
$('#texto').bind('cut copy paste', function(event) {
event.preventDefault();
});
});
If it's pure javascript, this inline template is for:
document.getElementById('texto').onpaste = function(){
return false;
}
If you do not 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.