By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Prevent user copy + pasting from one field to next

P: n/a
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

Sep 14 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a

em******@gmail.com wrote:
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. :-)

--
Rob

Sep 14 '06 #2

P: n/a
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.

Sep 14 '06 #3

P: n/a
rf
em******@gmail.com 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 :-)

--
Richard.
Sep 14 '06 #4

P: n/a

rf wrote:
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?

Sep 14 '06 #5

P: n/a
rf
em******@gmail.com
>
rf wrote:
>Hmmm. This user is filling out this form in anticipation of receiving
emails
from you?

yes, it's a sign up process
Thought so :-)
>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!
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.

--
Richard.

Sep 14 '06 #6

P: n/a

rf wrote:
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.

Sep 14 '06 #7

P: n/a

rf wrote:
em******@gmail.com
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.
I was hoping there was a javascript solution to this
Google for the "onbeforepaste" event, at least for IE users.

Cheers - Kev

Sep 14 '06 #8

P: n/a

Kevin Darling wrote:
rf wrote:
em******@gmail.com
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.
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

Sep 14 '06 #9

P: n/a

Kevin Darling wrote:
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.

Sep 14 '06 #10

P: n/a

em******@gmail.com написав:
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

Sep 14 '06 #11

P: n/a
JRS: In article <11*********************@m73g2000cwd.googlegroups. com>,
dated Thu, 14 Sep 2006 03:34:11 remote, seen in
news:comp.lang.javascript, em******@gmail.com posted :
>
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.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 14 '06 #12

P: n/a
Dr John Stockton said the following on 9/14/2006 6:46 PM:
JRS: In article <11*********************@m73g2000cwd.googlegroups. com>,
dated Thu, 14 Sep 2006 03:34:11 remote, seen in
news:comp.lang.javascript, em******@gmail.com posted :
>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.
That is very true. But, none of the onXXX can stop this scenario:

javascript:
document.formID.field1Name.value="em**********@som ewhere.com";
document.formID.field2Name.value="em**********@som ewhere.com";
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?
Sep 15 '06 #13

P: n/a
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="em**********@som ewhere.com";
document.formID.field2Name.value="em**********@som ewhere.com";
document.formID.submit();

From being executed in the address bar.
This one can [prevent the effect]:

<form onsubmit='return false'>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 15 '06 #14

P: n/a
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="em**********@so mewhere.com";
document.formID.field2Name.value="em**********@so mewhere.com";
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>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 15 '06 #15

P: n/a
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!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 15 '06 #16

P: n/a
em******@gmail.com 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.

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.
Just a thought, but perhaps onfocus you could assign the current length
of the field and setup an onkeyup check for length changes 1
if the change was only but one character you update the stored length
if it's greater than 1 , do your enforcement thing.
Sep 15 '06 #17

P: n/a
JRS: In article <Ha******************************@comcast.com>, dated
Thu, 14 Sep 2006 21:09:12 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.composted :
>Dr John Stockton said the following on 9/14/2006 6:46 PM:
>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="em**********@so mewhere.com";
document.formID.field2Name.value="em**********@so mewhere.com";
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 = "em**********@somewhere.com" ;
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.

--
John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v4.00 MIME
Prof Timo Salmi's Usenet Q&A <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqn.zip>
TS FAQs via : http://www.uwasa.fi/~ts/http/ : tsfaq.html quote margin &c.
My page <URL:http://www.merlyn.demon.co.uk/news-use.htmon usage of News.
Sep 15 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.