Disable copy paste in HTML input fields?

JavascriptHtmlSecurityPasswordsCopy Paste

Javascript Problem Overview


> Possible Duplicate:
> Disable Copy/Paste into HTML form using Javascript

My bank seem to have disabled copy-paste of username and password.

How is it done? Does it improve security?

Javascript Solutions


Solution 1 - Javascript

You can disable paste in your input as follows:

html:

<input type="text" value="" id="myInput">

javascript:

window.onload = () => {
 const myInput = document.getElementById('myInput');
 myInput.onpaste = e => e.preventDefault();
}

Talking about security, I wouldn't say that this makes any impact. You would usually use client side and well as server-side validation of data submitted by the user.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdam MatanView Question on Stackoverflow
Solution 1 - JavascriptIlya SidorovichView Answer on Stackoverflow