How to use EventListner In Javascript
An EventListener in JavaScript waits for a specified event, like a click or key press, on a DOM element and triggers a function to execute in response to that event.
Syntax:
const inputField = document.getElementById('email'); // fetch Id of Inputfield
inputField.addEventListener('paste', e => e.preventDefault());
Example: Below is an example of disabling ctrl+v in javascript using EventListner.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Text To Copy</h2>
<label>CRTL V Disabled </label><br>
<input type="text" id="email" required> <br><br>
<label>CRTL V Enabled </label><br>
<input type="text" id="pass" required>
<script>
const inputField =
document.getElementById('email');
inputField.addEventListener('paste', e => e.preventDefault());
</script>
</body>
</html>
Output: