-1

I'm in the middle of making a user registration form and want to prevent pasting into certain input boxes. Problem is, onPaste isn't being recognized as an event. As you can see in this image, onKeyPress is being recognized, whereas onPaste is not. https://i.stack.imgur.com/1FD5l.png

After some Googling it seems I am the only person on the planet who has encountered this (which probably means it's something silly and I'm a massive idiot). I'm using NetBeans IDE 8.2. Thanks in advance for any help.

The Lads
  • 1
  • 3
  • Yeah, there is a lot wrong with the clipBoard API at the moment: https://caniuse.com/#search=paste – Randy Casburn Jan 13 '19 at 00:09
  • 5
    Why would you punish people using password managers? Preventing people to paste passwords is really something you shouldn't do. See https://security.stackexchange.com/questions/131106/is-there-any-reason-to-disable-paste-password-on-login – Ivar Jan 13 '19 at 00:16
  • Maybe it's your IDE not recognizing `onpaste` event? Browsers mainly support it quite widely, as you can see behind randy's link. Btw. the image doesn't tell anything about "recognizing" onpaste event to those who are not familiar with the IDE, which's name you haven't included in the post ... – Teemu Jan 13 '19 at 00:22
  • If there is an issue, providing a minimal, complete, and verifiable example, would help a lot. See https://stackoverflow.com/help/mcve – Andrea Carraro Jan 13 '19 at 00:30
  • 1
    Apologies, I'm using NetBeans IDE 8.2 (I'll edit the post to include this). onPaste is being treated like it's a non-event attribute. Thanks Ivar duly noted; I'm fairly new to web design. – The Lads Jan 13 '19 at 00:39

3 Answers3

0

Try using onpaste instead of onPaste as it shows on the w3c example page. and what is the IDE are you using? try using a different syntax highlighting add-in or a plugin.

Dulara Malindu
  • 1,477
  • 4
  • 18
  • 37
  • 1
    W3Schools is **not** affiliated with W3C. ([And is often considered a bad resource.](https://meta.stackoverflow.com/questions/280478/why-not-w3schools-com)) – Ivar Jan 13 '19 at 00:43
  • Same result unfortunately. I'm using NetBeans IDE 8.2 but also tried it on Visual Studio 2017. – The Lads Jan 13 '19 at 03:01
0

function preventPasting(id) {
  console.log(id);
}
<input type="password" class="form-control" maxlength="50" id="password" onpaste="preventPasting(this.id)">

Change 'onPaste' with 'onpaste', maybe like this code.

For more documentation of onpaste : https://www.w3schools.com/jsref/event_onpaste.asp

Wicak
  • 399
  • 4
  • 12
0

Oops! As I suspected, I was being a massive idiot. onPaste doesn't appear to be recognized as an event in my IDE, but on run-time it will actually fire. My JavaScript code for the event was flawed and this is why nothing was happening.

Thanks for the help all.

The Lads
  • 1
  • 3