Mr.Cocococo Mr.Cocococo - 6 months ago 22
Javascript Question

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/

Answer

Check this fiddle fiddle

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

You need to bind What should be done on cut,copy paste.You prevent default behavior of the action. You can find detailed explanation here

Comments