3 ms·
> There are two ways to do this - a right way and a wrong way - using KeyboardEvent. I reject this strongly: they’re both wrong. It’s not reasonable to control
by chrismorgan 3y ago
> There are two ways to do this - a right way and a wrong way - using KeyboardEvent.
I reject this strongly: they’re both wrong. It’s not reasonable to control this via a KeyboardEvent at all. If you want to do this sort of thing, you should only manipulate in real-time based on the input’s value and selection, triggering on 'input' events when !event.isComposing. Otherwise, you will break things for some users.
Also, you should very, very strongly consider not manipulating the field contents, but only validating (and somewhat relaxed masking at that). The web just doesn’t give good, robust primitives for input masking.