JavaScript to block paste

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

JavaScript to block paste

Post by onion2k »

I'm trying to find a script that can block people simply copy'n'pasting things in forms .. I've got elements for people to confirm their password and email address .. and at a client's site yesterday it became clear that at least one user was entering their email address, copying it, and pasting it into the confirmation box. Kind of makes the whole thing a bit pointless..

Is there a way to stop pasting via javascript?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There is no definitive way I am aware of.. On the newer browsers you can hook the paste event, but it only takes a few clicks to disable Javascript if someone really wants to get around it.

Although it may penalize people that type excessively fast, you could look at using a change rate test. i.e. poll the fields for their value at a ~quick rate (30ms). If the value changes significantly since the last poll (like 3-5 characters) deny the change or something...
Post Reply