Created
July 17, 2014 14:06
-
-
Save benerdin/1d7a8b27c26eb0173a42 to your computer and use it in GitHub Desktop.
How to prevent pasting into a text field using jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('#elementId') | |
.keypress(function(e) { | |
// Prevent users from being able to type into the field. | |
e.preventDefault(); | |
}) | |
.keydown(function (e) { | |
// Prevent users from being able to type into the field. | |
e.preventDefault(); | |
}) | |
.keyup(function (e) { | |
// Prevent users from being able to type into the field. | |
e.preventDefault(); | |
}) | |
.bind('contextmenu', function(e) { | |
// Prevent users from being able to right-click and paste into the field. | |
e.preventDefault(); | |
}) | |
; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment