TIL prohibit inserting text
POSTED ON:
TAGS: forms javascript
You may want to prevent the user from pasting text copied from somewhere in the input fields (think carefully about whether it's worth it). This is very easy to do by tracking the event paste and calling its method
preventDefault()
.
<input type="text"></input>
<script>
const input = document.querySelector('input');
input.addEventListener("paste", function(e){
e.preventDefault()
})
</script>
Via https://dev.to/ra1nbow1/6-useful-frontend-techniques-that-you-may-not-know-about-47hd
Related TILs
Tagged: forms