views:

10767

answers:

10

Is there a way using Javascript to disable the ability to paste text into a text field on an HTML form?

E.g. I have a simple registration form where the user is required to input their email twice. The second email entry is to verify there are no typos in the first email entry. However if the user copy/pastes their email then that defeats the purpose and I've been experiencing users having problems because they've input the wrong email and copy/pasted it.

Thanks!

EDIT: Maybe I wasn't clear on my question but I am not trying to prevent people from copying (or drag selecting) text on their browser. I just want to stop them from pasting input into a text field to minimize user error.

Perhaps instead of using this "hack" you can suggest another solution to the core problem of what I'm trying to solve here? I've done less than half a dozen user tests and this has already happened twice. My audience does not have a high level of computer proficiency.

+5  A: 

You can..... but don't.

You should not be altering the default behaviour of a users browser. It really is bad usability for your web application. Also if a user wants to disable this hack then they can just disable javascript on their browser.

Just add these attributes to the textbox

ondragstart=”return false” onselectstart=”return false”
Sheff
+3  A: 

You could attach a "keydown" listener to the input box to detect whether or not the Ctrl + V keys are being pressed and, if so, stop the event or set the input box's value to ''.

That wouldn't handle right clicking and pasting or pasting from the Edit menu of the browser, though. You may need to add a "last length" counter to the keydown listener and use an interval to check the field's current length to see if it increase since the last keystroke.

Neither is recommended, though. Form fields with paste disabled are extremely frustrating. I'm capable of typing my email correctly the first time, so I reserve the right to paste it into the second box.

Kevin
Not right click or even anything from Apples, Unix or ctrl-ins, and how about iPhones?
Martlark
I am also not a big fan of disabling the input field as I find that frustrating myself. But what are the other options to stop this type of user error? Or which solution will end up with the least incorrectly completed user registrations? It seems a bit annoying to have to type in an email address manually again, but if it's going to save frustrated potential customers then I'd prefer to force users to manually type something into an input field. I'm thinking it's not a big inconvenience and the amount of frustration it could save someone from a simple mistake might be worht it. Thoughts?
justinl
+6  A: 

How about sending a confirmation email to the email address that the user has just entered twice in which there is a link to a confirmation URL on your site, then you know that they have got the message?

Anyone that doesn't click to confirm the receipt of the email may have entered their email address incorrectly.

Not a perfect solution, but just some ideas.

Richard
I have this implementation currently. The problem is that the user thinks they do not receive the email due to an error on our end because they check their email address that they *think* they entered and they do not have an email. Also what happens is that when they try to re-register again, the username that they used is now unavailable because it is stuck with that incorrect email address.
justinl
Tnen maybe add some workflow / code that runs everyday cleaning out usernames that have not been confirmed for say 2 days.
Colin
Thanks for the comment. My thoughts would be that if you tried to create an account on a website and it said that your user name was taken, would you go back again in 2 days and try it again? My thoughts are most likely not. Either you've created a new account with a different username the same day or you've not bothered coming back to the site because you couldn't figure out how to register and the site was "too complicated".
justinl
To continue what Colin is saying, you could possibly assume that when someone is trying to re-register with the same username and a different email address and they haven't responded to the confirmation message it's probably okay to let them do so. You might find that people get their domain correct in their email but misspell their username and could use this to further determine when someone has made a mistake?
Richard
I really like that idea of allowing users to re-register who have not yet confirmed their account information. I think this design solution is better than my original proposed technical solution. Hearing form everyone else that changing this default browser functionality was a bad idea was what I needed to hear to find a better solution.
justinl
+2  A: 

Add a second step to your registration process. First page as usual, but on reload, display a second page and ask the email again. If it's that important, the user can handle it.

Alsciende
+4  A: 
Christopher Parker
+2  A: 

Crazy idea: Require the user to send you an email as part of the signup process. This would obviously be inconvenient when clicking on a mailto link doesn't work (if they're using webmail, for example), but I see it as a way to simultaneously guarantee against typos and confirm the email address.

It would go like this: They fill out most of the form, entering their name, password, and whatnot. When they push submit, they're actually clicking a link to send mail to your server. You've already saved their other information, so the message just includes a token saying which account this is for.

jleedev
Ha, that is a neat idea.
justinl
+2  A: 

<editorial>

Don't do it. Don't mess with the user's browser. By Copy + Pasting into an E-Mail confirmation field, the user accepts responsibility over what they type. If they are dumb enough to copy + paste a faulty address (it has happened to me) then it's their own damn fault.

If you want to make sure that the E-Mail confirmation works out, have the user check their E-Mail while your site waits ("Please open your webmail program in a new window"). Show the E-Mail address in big fat letters ("The confirmation E-Mail was sent to.... made an error? CLick here to change).

Even better, if you can, let the user have some kind of limited access without confirming. That way, they can log in straight away and you improve your chances to keep in touch with the visitor even if the confirmation mail is blocked due to other reasons (e.g. spam filters).

</editorial>

Pekka
A: 

what about using CSS on UIWebView? something like

<style type="text/css">
<!—-
    * {
        -webkit-user-select: none;
    }
-->
</style>

also you can read detail about block copy-paste using CSS http://rakaz.nl/2009/09/iphone-webapps-101-getting-safari-out-of-the-way.html

A: 

ondragstart=”return false” onselectstart=”return false” these are not the attributes on a Input type=text.

Not sure how this is working...

any custom java script should be return

bpl
A: 

looks nice, clever and promissing :)

Alan