Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable copy paste in HTML input fields? [duplicate]

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?

like image 854
Adam Matan Avatar asked Oct 09 '12 18:10

Adam Matan


People also ask

How do I stop copy paste input field?

The onpaste attribute lets us prevent pasting into the form. Adding the autocomplete attribute as well as preventing drag and drop into the element. If you want to avoid the on{event} code in the HTML, you can do it the cleaner way: myElement.

How do I turn off copy and paste in HTML?

You can use jquery for this: $('body'). bind('copy paste',function(e) { e. preventDefault(); return false; });

How do I stop HTML from copying text from a website?

Here: How to disable text selection highlighting using CSS? -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; Disallow them from being able to answer when the window's onBlur event is fired.

How can we avoid copy paste in TextBox using jQuery?

Projects In JavaScript & JQuery To disable cut, copy and paste of a content in jQuery, use the jQuery bind() function.


1 Answers

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.

like image 81
Ilya Sidorovich Avatar answered Sep 21 '22 16:09

Ilya Sidorovich