How can I disable Paste (Ctrl+V) option using jQuery in one of my input text fields?
To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.
You can use jquery for this: $('body'). bind('copy paste',function(e) { e. preventDefault(); return false; });
The event. preventDefault() method stops the default action of an element from happening. You can use this method toprevent a TextBox control from Cut (Ctrl+X) , Copy (Ctrl+C) and Paste (Ctrl+V) .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With