How can I disable Paste (Ctrl+V) option using jQuery in one of my input text fields?
-
12Why would you do that? It would frustrate more then one user if you disable ctrl+v. besided you can always right click and select paste – Christophe Apr 01 '11 at 07:06
-
8@krike maybe to force people to retype their email address or password? – greggreg Apr 01 '11 at 07:11
-
5I will disable JS in browser and can put ctrl+v anytime. – Kamilos Apr 01 '11 at 07:31
-
2@Kamilos what if the site requires javascript to run? – greggreg Apr 01 '11 at 07:32
-
7@Kamilos what about banking or facebook? if you disable javascript we cant even post comments in stack overflow. – greggreg Apr 01 '11 at 07:57
-
18@greg: "to force people to retype their email address" - and pray tell, what is the point in that? If you are already setting up pointless tricks like "type in your address twice, to see if you actually remember it", and then mess with my clipboard, just to show me who's in charge, I'm leaving - if *that* is an attempt to make a good first impression, then I fully expect the site to be terrible. – Piskvor left the building Apr 01 '11 at 11:46
-
3Based on a true story: I know this is old, but here's a perfectly valid case in where to ask the user to retype the email address: The user is buying some online tickets for an event, he is not registered in the website and the only way he'll receive his tickets is in the provided email address. If the user misspells the address, he won't receive the tickets. Then he'll blame the "crappy system that doesn't work and don't send the tickets" and give the support team more work by tons of emails and phone calls – hectorg87 Apr 21 '14 at 08:10
-
1Disabling paste is a security nightmare. Sensible users use a password manager with long random passwords that no human can remember. The user copies and pastes the passwords from the password manager to the login, thus benefitting from strong, unique-per-web site passwords and resilience to keyboard logging malware and hardware. – David Johnston Oct 13 '15 at 05:02
-
@DavidJohnston password managers now have an auto-fill option – David Gras Nov 23 '15 at 10:37
-
1@daVe ...which have their own security implications. Also a "smart" web page might prevent that too. – David Balažic Apr 06 '17 at 12:41
-
Another situation where this would be valid is the text input field, which simulates number/decimal input (it may be the best solution if you want to set proper decimal separator for multilanguage apps, as default number/decimal input does no handle it very well). Obviously you may want to prevent users from pasting some invalid strings there. So I would rather focus on the question itself than dispute whether someones solution is proper or not, especially if we don't know any details. – Daniel Stasiak Apr 10 '20 at 07:43
11 Answers
This now works for IE FF Chrome properly... I have not tested for other browsers though
$(document).ready(function(){
$('#txtInput').on("cut copy paste",function(e) {
e.preventDefault();
});
});
Edit: As pointed out by webeno, .bind()
is deprecated hence it is recommended to use .on()
instead.

- 4,320
- 2
- 25
- 43
-
12$('#txtInput').bind("contextmenu",function(e){ e.preventDefault(); });//This disables the right-click – Misam Apr 01 '11 at 09:21
-
3Interesting, I didn't know these events existed. I've found this page on browser quirks mode that gives info on cross browser compatability for these events: http://www.quirksmode.org/dom/events/cutcopypaste.html – DannyLane Apr 01 '11 at 12:51
-
-
wow, this is great! You can disable the contextmenu but the greatest thing is that it's not necesary! – David Gras Nov 23 '15 at 10:43
-
1**NOTE** "As of jQuery 3.0, .bind() has been deprecated. It was superseded by the .on() method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged." -- Source: http://api.jquery.com/bind/ – benomatis Mar 09 '18 at 20:35
-
***`cut`, `copy`, and `paste` are experimental (but i believe widely supported)*** – oldboy Nov 07 '20 at 00:09
Edit: It's almost 6 years later, looking at this now I wouldn't recommend this solution. The accepted answer is definitely much better. Go with that!
This seems to work.
You can listen to keyboard events with jQuery and prevent the event from completing if its the key combo you are looking for. Note, check 118 and 86 (V and v)
Working example here: http://jsfiddle.net/dannylane/9pRsx/4/
$(document).ready(function(){
$(document).keydown(function(event) {
if (event.ctrlKey==true && (event.which == '118' || event.which == '86')) {
alert('thou. shalt. not. PASTE!');
event.preventDefault();
}
});
});
Update: keypress doesn't fire in IE, use keydown instead.

- 2,096
- 1
- 16
- 17
-
Won't work for rightclick+paste, or for those "multimedia keys"; These are using different mechanisms than keyboard shortcuts. Also, you're assuming that paste is always and only at Ctrl+V – Piskvor left the building Apr 01 '11 at 11:50
-
@Piskvor I'm not making any assumptions, the question was how to disable ctrl+v which is what I answered. – DannyLane Apr 01 '11 at 11:57
-
@DannyLane: You are right. I've understood the question to be "disable paste altogether", but that may not be what the OP wants. – Piskvor left the building Apr 01 '11 at 12:36
-
Thanks for that - was using keypress and couldn't figure out why it didn't work in IE – Addsy Jun 21 '11 at 15:12
-
@DannyLane: On different platforms there could be different key bindings for "paste" action. – dma_k Sep 10 '15 at 12:53
-
When hit ctrl+v, it works. However when right click + paste, it's out of control. – funbrain9 Jul 29 '22 at 05:05
I tried this in my Angular project and it worked fine without jQuery.
<input type='text' ng-paste='preventPaste($event)'>
And in script part:
$scope.preventPaste = function(e){
e.preventDefault();
return false;
};
In non angular project, use 'onPaste' instead of 'ng-paste' and 'event' instesd of '$event'.

- 346
- 6
- 17
The following code will disable cut, copy and paste from full page.
$(document).ready(function () {
$('body').bind('cut copy paste', function (e) {
e.preventDefault();
});
});
The full tutorial and working demo can be found from here - Disable cut, copy and paste using jQuery

- 1,803
- 20
- 11
$(document).ready(function(){
$('#txtInput').on("cut copy paste",function(e) {
e.preventDefault();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="txtInput" />

- 465
- 4
- 12
jQuery('input.disablePaste').keydown(function(event) {
var forbiddenKeys = new Array('c', 'x', 'v');
var keyCode = (event.keyCode) ? event.keyCode : event.which;
var isCtrl;
isCtrl = event.ctrlKey
if (isCtrl) {
for (i = 0; i < forbiddenKeys.length; i++) {
if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
return false;
}
}
}
return true;
});

- 1,629
- 5
- 21
- 37
$(document).ready(function(){
$('#txtInput').live("cut copy paste",function(e) {
e.preventDefault();
});
});
On textbox live event cut, copy, paste event is prevented and it works well.

- 148
- 2
- 7
-
-
1`$(document).ready(function(){...})` could be re-written to equivalent `$(function(){...})`. – dma_k Sep 10 '15 at 12:50
-
Immediately Invoked Function Expression (IIFE) can also be used.(function() { }()); – Vikas Bansal Sep 17 '15 at 14:43
I have tested the issue on chrome browser and it is working for me.Below is a solution for preventing the paste code in your textbox and also prevent the right click.
$(".element-container").find('input[type="text"]').live("contextmenu paste", function (e) {
e.preventDefault();
});

- 529
- 6
- 10
You can catch key event :
function checkEventObj ( _event_ ){
// --- IE explorer
if ( window.event )
return window.event;
// --- Netscape and other explorers
else
return _event_;
}
document.keydown = function(_event) {
var e = checkEventObject(_event);
if( e.ctrlKey && (e.keyCode == 86) )
window.clipboardData.clearData();
}
Not tested but, could help.
Source from comentcamarche and Zakaria

- 3,103
- 6
- 26
- 28
-
2`window.clipboardData.clearData()` only works in ie. If you're catching the event you might as well just prevent default and return false. that would effectively disable keyboard initiated paste. I'd post the example but i'm too lazy, and plus you're already so close. – greggreg Apr 01 '11 at 07:28
$(document).ready(function(){
$('input').on("cut copy paste",function(e) {
e.preventDefault();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" />

- 73
- 1
- 1
- 5