Question: I have some information to enter in a text box. The data is structured and only some sequences are valid. For a phone number, for instance, a letter such as `A` is invalid.

So should I intercept keyboard events and prevent typed letters from reaching the text box, or should I draw some red squiggly lines (or another visual cue) to let my user know the letter is not acceptable? Which is a better user experience?

Answer: 
Being on both ends of using a form, here are some guidelines I prefer:

* User inputs should hardly ever be prevented. Meaning if I type the letter 'A' in a phone number field, I would expect to see that 'A'.
* I begin my text field validation on a `onBlur()` event, and no sooner than that. This gives the user a chance to fix that mis-typed 'A' before I show an error message. Allowing the user to correct an error while still in the input field provides one less chance for an obtrusive "hey, you messed up, dude" kind of message.
It depends on the case. If possible use Auto-suggest. If you intercepts user's input, an immediate feedback is crucial. One of the possible solutions is "clue box" that pops up immediately after key is intercepted. You can see it on Windows login screen, it pops up if you press $ sign for instance.