Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Copy or Paste action for text box?

I have two textboxes, and I want to prevent user from copying the value from the first (email) textbox and pasting it in the second (confirmEmail) textbox.

Email: <input type="textbox" id="email"><br/> Confirm Email:    <input type="textbox" id="confirmEmail"> 

I have two solution in my mind:

  1. Prevent copy action from the email textbox, or
  2. Prevent paste action from the confirmEmail textbox.

Any idea about how to do it?

http://jsfiddle.net/S22ew/

like image 471
Mr.Cocococo Avatar asked Jun 26 '14 06:06

Mr.Cocococo


People also ask

How do I enable copy paste in TextBox?

Use KeyPress, KeyUp, KeyDown for the same... <asp:TextBox onkeypress="return false;" onkeyup="return false;" onkeydown="return false;" ... You can use javascript key events for this. Use KeyPress, KeyUp, KeyDown for the same...

How can we avoid copy paste in TextBox using jQuery?

Projects In JavaScript & JQuery To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.


1 Answers

Check this fiddle.

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

You need to bind what should be done on cut, copy and paste. You prevent default behavior of the action.

You can find a detailed explanation here.

like image 194
Pratik Avatar answered Sep 29 '22 11:09

Pratik