Prevent user copy + pasting from one field to next

E

emma.sax

Hi all,

I have a form where we would like the user to input their email address
twice, to ensure they've typed it correctly, as is found on most
sign-ups

I'm looking for a solution to the problem where a user (and me it has
to be said) just either highlights the email address with their mouse
(or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click
paste) into the next field down.

How would I go about this in JavaScript, or is there another solution?

If it were up to me, I'd use just one box for the email address - but
it isn't, so it has to be done twice.

Thanks

M
 
R

RobG

Hi all,

I have a form where we would like the user to input their email address
twice, to ensure they've typed it correctly, as is found on most
sign-ups

I'm looking for a solution to the problem where a user (and me it has
to be said) just either highlights the email address with their mouse
(or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click
paste) into the next field down.

How would I go about this in JavaScript, or is there another solution?

The only way to prevent copy & paste to a second field is to not have a
second field. :)
 
E

emma.sax

The only way to prevent copy & paste to a second field is to not have a
second field. :)

:) mm, I realise it's a pretty dumb question - but is there any
javascript solution.
 
R

rf

(e-mail address removed) wrote
I have a form where we would like the user to input their email address
twice, to ensure they've typed it correctly, as is found on most
sign-ups

I'm looking for a solution to the problem where a user (and me it has
to be said) just either highlights the email address with their mouse
(or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click
paste) into the next field down.

Hmmm. This user is filling out this form in anticipation of receiving emails
from you?

If they do it incorrectly, by either copy/pasting drag/dropping an incorrect
address or even typing an incorrect address twice then is it not *their*
problem? Even if you do everything in your power to protect yourself against
fools then very shortly a better fool will come along :)
 
E

emma.sax

rf said:
Hmmm. This user is filling out this form in anticipation of receiving emails
from you?

yes, it's a sign up process
If they do it incorrectly, by either copy/pasting drag/dropping an incorrect
address or even typing an incorrect address twice then is it not *their*
problem? Even if you do everything in your power to protect yourself against
fools then very shortly a better fool will come along :)

very much agreed, but it is a company decision to use 2 boxes and not
mine!

I was hoping there was a javascript solution to this - if anyone can
point in the direction of what methods i might use etc?
 
E

emma.sax

rf said:
So, look around. Many sign up processes uses two boxes. None of these (that
I have seen) prohibit copy/paste etc. Why should yours? Is this a "boss
directive" that you disallow copy/paste etc? If so then you should advise
your boss accordingly.

I guess I'm going to have to!
Or are you inventing a problem that everybody else has simply ignored?

Yeah, it isn't really a problem at all - not in the grand scheme of
forms.
Once again, if your user stuffs up their sign-up process it is IMHO that
users fault, not yours.

Ok, brilliant Richard. Thanks for all your information.
 
R

rf

(e-mail address removed)
yes, it's a sign up process

Thought so :)
very much agreed, but it is a company decision to use 2 boxes and not
mine!

So, look around. Many sign up processes uses two boxes. None of these (that
I have seen) prohibit copy/paste etc. Why should yours? Is this a "boss
directive" that you disallow copy/paste etc? If so then you should advise
your boss accordingly.

Or are you inventing a problem that everybody else has simply ignored? It is
IMHO not your problem. If somebody willingly duplicates an incorrect address
then that person is not really using your sign up process correctly. I for
one *like* the two boxes, it checks for my typos and *I* never copy/paste.
What would be the point?
I was hoping there was a javascript solution to this

I really don't think there is one.
- if anyone can
point in the direction of what methods i might use etc?

Carrying on from my previous comments, if you can stop every browser from
allowing this copy/paste etc in all its variations then the day after
tomorrow some browser will provide a different method of duplicating the
content of those boxes.

Once again, if your user stuffs up their sign-up process it is IMHO that
users fault, not yours.

I run several opt-in email lists. If a user signs up with an incorrect email
address and it bounces just once then they are out.
 
K

Kevin Darling

rf said:
(e-mail address removed)
So, look around. Many sign up processes uses two boxes. None of these (that
I have seen) prohibit copy/paste etc. Why should yours?

Clearly you don't get around much. More and more sites attempt to
prevent pasting when entering important information twice. Travel
billing, banks, and even state DMV's asking for vehicle info, they all
do it.

Google for the "onbeforepaste" event, at least for IE users.

Cheers - Kev
 
K

Kevin Darling

Kevin said:
Clearly you don't get around much.

Actually, that was a bit harsh of me, although you were really giving
the OP grief :). Perhaps you never noticed all the sites that do
this, because you use a browser that doesn't allow stopping a paste.

In any case, it's a very smart move, especially on sites where you have
to enter long series of numbers. Entering a credit card number comes
to mind.

Cheers - Kev
 
E

emma.sax

Kevin said:
Google for the "onbeforepaste" event, at least for IE users.

Thanks, Kevin. I'll probably try implementing it for IE users and
it'll just be open for everyone else.
 
S

scriptguru

(e-mail address removed) напиÑав:
Hi all,

I have a form where we would like the user to input their email address
twice, to ensure they've typed it correctly, as is found on most
sign-ups

I'm looking for a solution to the problem where a user (and me it has
to be said) just either highlights the email address with their mouse
(or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click
paste) into the next field down.

How would I go about this in JavaScript, or is there another solution?

If it were up to me, I'd use just one box for the email address - but
it isn't, so it has to be done twice.

Thanks

M
In IE you just need to handle onPaste or/and onCopy event.
In any modern browser you can handle onKeyUp event and if user tries to
push something except alphanumerals and punctuation just return false.

Val
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Thu, 14 Sep 2006 03:34:11 remote, seen in
I have a form where we would like the user to input their email address
twice, to ensure they've typed it correctly, as is found on most
sign-ups

I'm looking for a solution to the problem where a user (and me it has
to be said) just either highlights the email address with their mouse
(or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click
paste) into the next field down.

How would I go about this in JavaScript, or is there another solution?

It's too late for me to test this tonight, but how about using one of
the onXXXX operations to examine the timing of the entries?

Needs to do both, unless you force entering the first one first.

Even a trained typist cannot type an entry as fast as copy'n'paste
enters it.

Anything in javascript may be defeated by using a forged page; but you
are presumably considering only moderately co-operative clients.

Thought : can onSubmit send a checksum of body innerHTML - probably -
execute document.write(document.body.innerHTML) in my js-quick.htm!

It's a good idea to read the newsgroup and its FAQ.
 
R

Randy Webb

Dr John Stockton said the following on 9/14/2006 6:46 PM:
JRS: In article <[email protected]>,
dated Thu, 14 Sep 2006 03:34:11 remote, seen in


It's too late for me to test this tonight, but how about using one of
the onXXXX operations to examine the timing of the entries?

Needs to do both, unless you force entering the first one first.

Even a trained typist cannot type an entry as fast as copy'n'paste
enters it.

That is very true. But, none of the onXXX can stop this scenario:

javascript:
document.formID.field1Name.value="(e-mail address removed)";
document.formID.field2Name.value="(e-mail address removed)";
document.formID.submit();

From being executed in the address bar.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
E

Evertjan.

Randy Webb wrote on 15 sep 2006 in comp.lang.javascript:
That is very true. But, none of the onXXX can stop this scenario:

javascript:
document.formID.field1Name.value="(e-mail address removed)";
document.formID.field2Name.value="(e-mail address removed)";
document.formID.submit();

From being executed in the address bar.

This one can [prevent the effect]:

<form onsubmit='return false'>
 
R

Randy Webb

Evertjan. said the following on 9/15/2006 3:14 AM:
Randy Webb wrote on 15 sep 2006 in comp.lang.javascript:
That is very true. But, none of the onXXX can stop this scenario:

javascript:
document.formID.field1Name.value="(e-mail address removed)";
document.formID.field2Name.value="(e-mail address removed)";
document.formID.submit();

From being executed in the address bar.

This one can [prevent the effect]:

<form onsubmit='return false'>

You may want to test that a little more. formRef.submit() doesn't
trigger the onsubmit event handler:

<form onsubmit="alert('I got fired');return false" target="_blank">
<input type="button" onclick="this.form.submit()"
value="Submit via Script">
<input type="submit" value="Submit without script">
</form>
 
E

Evertjan.

Randy Webb wrote on 15 sep 2006 in comp.lang.javascript:
You may want to test that a little more. formRef.submit() doesn't
trigger the onsubmit event handler:

<form onsubmit="alert('I got fired');return false" target="_blank">
<input type="button" onclick="this.form.submit()"
value="Submit via Script">
<input type="submit" value="Submit without script">
</form>

;-{

You got fired for submitting the truth to me like that, Randy!
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Thu, 14 Sep 2006 21:09:12 remote, seen in
Randy Webb said:
Dr John Stockton said the following on 9/14/2006 6:46 PM:

That is very true. But, none of the onXXX can stop this scenario:

javascript:
document.formID.field1Name.value="(e-mail address removed)";
document.formID.field2Name.value="(e-mail address removed)";
document.formID.submit();

From being executed in the address bar.

Granted; and one could probably edit the page locally to circumvent any
checks.

But the OP seems to be trying to inhibit naive users from not benefiting
from the double-typed input check - and your code does have double
input.

javascript: with (document.formID) {
field1Name.value = field2Name.value = "(e-mail address removed)" ;
submit() }

(untested) seems a more efficient cheat.

But the OP only needs to have a hidden field containing the results of
the timing tests ...
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

Oversize sigs used to be - they seem to be coming back here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top