I have email and confirm email fields. I do not want the user to copy and paste in confirm field. Is there a way to do that?
Question
Question
Replies
You could try binding an event handler to the cut, copy, and paste, events for the fields.
However, this doesn't make for a great user experience since the user may not understand what's happening and I can't think of any other sites I've encountered where this is prevented other than rare instances with password entry fields, and even then it is annoying.
For example, if they try to copy and paste and it just doesn't work, they would likely try at least one more time because blocking of that functionality is not something anyone would expect.
If you really want to do it, the code would be something like this, but I wouldn't do it.
$(document).ready(function(){ $('.noCopyPaste input').on('cut copy paste', function(e){ e.preventDefault(); }); });
I have to second Jason's point about the poor user experience. With the increase in use of credential managers etc., this will mostly just prevent users from pasting in a known good email string. I've encountered this restriction a few times and always found it quite irritating, especially on mobile devices where typing out email strings can be tedious.
If the form is for authenticated users, I'd recommend using the built-in email token to auto-fill the first email field as read-only. Then have a checkbox for "Use a different email" which unlocks the first email field and displays the second confirmation one (which you'd check for a match). That way they don't need to deal with confirming the email associated with their account.
Thank you all.