TAGS :Viewed: 23 - Published at: a few seconds ago

[ Restrict user from copying their own text written in input feild ]

I have one input box for email on my website

<input type="text" name="email" class="box" id="email" value="Enter your email">
<input type="text" name="confirmEmail" class="box" id="confirmEmail" value="Enter your email again">

By using css below we can restrict user from selecting any content

 *{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    }

I wanted to know, is it possible to restrict user from copying their own written text in any input boxes? if yes how? I want my users to write their email two time instead of copy paste.

Answer 1


A bit of googling before posting here mate would be good...Anyway here is how to disable cut,copy and paste. Don't forget to include jQuery before the code below.

$(document).ready(function(){
  $('#confirmEmail').live("cut copy paste",function(e) {
      e.preventDefault();
  });
});

Validating an email with regular expression would help you for your scenario as well.

Answer 2


 document.getElementById("confirmEmail").addEventListener('paste',
    function(e){e.preventDefault()});

 document.getElementById("confirmEmail").addEventListener('drop',
   function(e){e.preventDefault()});

http://jsfiddle.net/vPXrR/1/

update

 document.getElementById("email").addEventListener('paste',
     function(e){e.preventDefault()});
 document.getElementById("email").addEventListener('drop',
    function(e){e.preventDefault()});

http://jsfiddle.net/vPXrR/2/