Preventing copy-paste into textfields


You can prevent the copy-paste functionality into textfields of your web-forms using a very simple jquery method.
First include the jquery file in between  the <head> tag.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

Then add the following code to the <head> tag, below the include script.

<script type="text/javascript">// <![CDATA[
 $(document).ready(function () {
 $('input[type=text]').bind('copy paste', function (e) {
 e.preventDefault();
 });
 });
 // ]]>
 </script>

The above code will prevent copy and paste to and from any textfields of your form.

You can also use the id of the form fields to refer and block the copy-paste. This can be acheived by replacing the part $('input[type=text]') with $('#id_of_textbox') , in the above function.

  1. No comments yet.
(will not be published)