X-mas Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now
Disable cut, copy and paste in textbox using jquery, javascript

Disable cut, copy and paste in textbox using jquery, javascript

13 Feb 2024
Beginner
21.9K Views
1 min read
Learn with an interactive course and practical hands-on labs

Free ReactJS Foundation Course: React JS Online Course Free

Due to some reasons (like don’t allow to copy Email from Email TextBox to Confirm Email TextBox), we restrict users to copy, paste and cut contents from TextBox by using CTRL+C, CTRL+V and CTRL+X. We can implement this functionality by using below methods.

Disable cut, copy & paste using Javascript

  1. When we don't want to display any message on cut, copy & paste

     <asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"></asp:TextBox> 

  2. When we want to display an alert message on copy, paste and cut

     <script language="javascript" type="text/javascript">
    function DisableCopyPaste (e) 
    {
     // Message to display
     var message = "Cntrl key/ Right Click Option disabled";
     // check mouse right click or Ctrl key press
    var kCode = event.keyCode || e.charCode; 
    //FF and Safari use e.charCode, while IE use e.keyCode
     if (kCode == 17 || kCode == 2)
     {
     alert(message);
     return false;
     }
    }
    </script>
     <asp:TextBox ID="TextBox1" runat="server" onKeyDown="return DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste (event)"></asp:TextBox> 

Read More - Advanced jQuery Interview Questions and Answers

Disable cut, copy & paste using JQuery

 <script type="text/javascript">
$(document).ready(function() {
 $('#TextBox1').bind('copy paste cut',function(e) { 
 e.preventDefault(); //disable cut,copy,paste
 alert('cut,copy & paste options are disabled !!');
 });
});
</script>
 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox> 
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this