Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  160] [ 2]  / answers: 1 / hits: 23935  / 12 Years ago, thu, may 31, 2012, 12:00:00

I have two fields, one is emailid and another is password in my form. I want to prevent the user from pasting into those fields. They should be forced to enter manually, like Google Forms.


More From » html

 Answers
8

You could disable ctrl+v combination and right click as well.



for IE, you may tap into following event handlers:



onpaste=return false; 
oncut=return false;
oncontextmenu=return false;
oncopy=return false;.


Here is a workaround for all browsers:



function noCTRL(e) {
var code = (document.all) ? event.keyCode : e.which;
var ctrl = (document.all) ? event.ctrlKey : e.modifiers & Event.CONTROL_MASK;
var msg = Sorry, this functionality is disabled.;
if (document.all) {
if (ctrl && code == 86) {
//CTRL+V
alert(msg);
window.event.returnValue = false;
} else if (ctrl && code == 67) {
//CTRL+C (Copy)
alert(msg);
window.event.returnValue = false;
}
} else {
if (ctrl == 2) {
//CTRL key
alert(msg);
return false;
}
}
}


In HTML section, your fields would look like:



Email :<input name=email type=text value=/><br/>
Password :<input name=password type=password value=/><br/>
Confirm Email :<input name=email type=text value= onkeydown=return noCTRL(event)/>
Confirm Password :<input name=password type=password value= onkeydown=return noCTRL(event)/>


I don't think user can copy password fields if input type is password



Hope this helps.



Note:




  1. Disabling JavaScript in browser will let users do whatever they want

  2. Always Keep this in mind: respect user's freedom.


[#85248] Wednesday, May 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
muhammadbrandend

Total Points: 670
Total Questions: 95
Total Answers: 97

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;