Reputation: 387
I want to prevent people from pasting password in login form. Is it possible by PHP to disable the ability to paste into input fields.
Upvotes: 2
Views: 10787
Reputation: 3083
$(document).ready(function() {
$('#password').bind("cut copy paste", function(event) {
event.preventDefault();
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="password" id="password">
Upvotes: 0
Reputation: 23816
You can simply do this with HTML
by adding some properties to input
.
I don't know why you want to use
PHP
for this.
<input type="test" onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false"/>
Upvotes: 6
Reputation: 15336
In Jquery you can do like this to disable copy paste on whole Page
$('body').bind('copy paste',function(e) {
e.preventDefault(); return false;
});
Upvotes: 2
Reputation: 1380
You can not do it using php, because it is server side scripting language. you will have to handle this situation using javascript or Jquery
Following are the options which can help.
$(document).ready(function(){
$('#txtInput').bind("cut copy paste",function(e) {
e.preventDefault();
});
});
jQuery('input.disablePaste').keydown(function(event) {
var forbiddenKeys = new Array('c', 'x', 'v');
var keyCode = (event.keyCode) ? event.keyCode : event.which;
var isCtrl;
isCtrl = event.ctrlKey
if (isCtrl) {
for (i = 0; i < forbiddenKeys.length; i++) {
if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
return false;
}
}
}
return true;
});
Thanks Amit
Upvotes: 0
Reputation: 709
Use below code HTML
<input type="password" id="pwd">
Jquery
$('#pwd').bind("cut copy paste",function(e) {
e.preventDefault();
});
Upvotes: 2
Reputation: 1030
Use this to disable paste in your input as follows:
html:
<input type="text" value="" id="myInput" />
javascript:
window.onload = function() {
var myInput = document.getElementById('myInput');
myInput.onpaste = function(e) {
e.preventDefault();
}
}
Upvotes: 0