View Full Version : Stop cut and paste from textbox
07-11-2003, 02:08 PM
Does anybody know how to stop people cutting and pasting from a text box.
I have a page where I ask users to enter their email address twice - 2nd time to verify no typing mistakes. At the moment they can just cut and paste from one to the other. This makes the whole thing pointless so I would like to stop the ability to do this on the page.
Is it possible and how?
Thank you in advance.
07-11-2003, 04:12 PM
Use a key event (onkeydown, onkeypress, onkeyup) and two counters. Then make sure the counters are both positive numbers before submitting (they won't be equal if the user types a backspace or delete). I'm fairly certain the paste will not increment the counters since it isn't a key event.
07-11-2003, 05:38 PM
Thanks for that,
I may have to implement something like that if I can't find what I'm after. It will enable me to check that they didn't cut and paste the address, but what I was after was something that didn't let them do it at all.
I am sure (as sure as I can be) that once I went on a website which wouldn't allow me to highlight the text I had input into the box - so I couldn't copy it and had to re-type it.
That's what I am really after! But if it's not possible I think your suggestion is a workaround.
thanks for the help.
07-11-2003, 06:00 PM
<input onselect="this.blur()" ...
07-11-2003, 06:10 PM
Thanks, but that didn't work either. My text box code is like this..
<input type="text" name="address" size="25" maxlength="40" onselect="this.blur()">
and I can cut and paste using mouse or keyboard - even drag and drop!
Im using IE explorer 6 browser. Could this be part of the problem?
07-11-2003, 06:12 PM
Let's see, let me count the ways to copy and paste (and this is only Windows!)
1) Ctrl + C | Ctrl + V
2) Ctrl + Ins | Shift + Ins
3) Right-click >> Copy | Right-click >> Paste
4) Select text | Ctrl-drag'n'drop
5) Edit >> Copy | Edit >> Paste
You can't directly prevent #5, and you can possibly do something about 1-4, but not without a lot of headache.
Personally, I don't think it's worth the effort.
If you MUST have a solution, then I can only offer this IE5+ fix
<input type="text" onpaste="event.returnValue=false" ondrop="event.returnValue=false"/>
However, you'll likely make people think you're site is busted and just piss them off. I don't recommend this, but there it is.
And, of course, Mozilla et al., Opera, etc won't be affected by this fix.
07-11-2003, 06:28 PM
damn IE strikes again.... add this:
<input onselect="this.blur()" onselectstart="return false;" .....
07-11-2003, 06:44 PM
Thanks all for your help.
In the end Vladdy it did work - on IE 6.0.:thumbsup:
I won't even bother to check other browsers as the weekend is here.
But next week.......
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.