

CODE PASTEBOX PASSWORD
If you're trying to prevent somebody from mistyping a password or email a second time, why not hook the oncopy event from the box you're trying to confirm.

While I totally disagree with the incentive to do something like this, I feel like that opinion might already be fully fleshed-out in other comments.Īlternatively, why not consider the UX of this and explicitly which behavior you're trying to prevent. It's a good idea to consider questions like this when building your site in order to provide the best experience for your users. Additionally, if the user decides to copy and paste data into a form field at the risk of it containing typos, then we should allow them to do this.Įach website is different, so there is no definitive answer. The posters argue against changing expected browser behaviour because it will confuse users. The answers to this StackOverflow question about the paste event discourage developers from tampering with default browser behaviour.
CODE PASTEBOX HOW TO
Now you know how to change the expected behaviour of the paste event in your webpage, the question is whether you should. See the caniuse table for the Clipboard API for more information. The Clipboard API also includes accessing the contents of the clipboard, which has varying levels of support. These events are part of the Clipboard API. There is good support for the paste event in modern browsers. There are also events for the cut and copy action. When the user tries to paste content into the field, using either a keyboard shortcut or context menu, nothing will happen.

pasting the contents of the clipboard into the input element).
CODE PASTEBOX CODE
This code cancels the default behaviour of the paste event (i.e. We can use JavaScript to target an input field’s paste event and change how it works:Įnter fullscreen mode Exit fullscreen mode How is this functionality achieved? How can you stop your users from pasting content into a HTML input field? The idea is to make users type their email or password twice to help catch any typos they might have made in those important "Email" and "Password" values. In some forms, the “Confirm email address” or “Confirm password” fields don't allow users to paste text into them. Thank you to the Dev community members for all of your comments and feedback and for making this site such a positive part of the internet! However, I also strongly encourage you to read the discussion below this post, as it clearly shows how unwanted and unnecessary this feature is. My intention with this post was to remain unbiased about whether you should or should not do this, and to encourage you to make your own decision. Edit 01/02/19: I was frustrated by yet another web form that wouldn’t let me paste my password into the Confirm Password field, wondered how it was done and decided to write about it.
