I've been having a debate (mostly with myself) over the best approach to deal with invalid input in text fields -- validation versus prevention.
Taking a numeric text field as an example, is it better to prevent the entry of non-numeric characters (allowing for special cases like sign, decimal pt., etc.) or allow the entry of whatever and then indicate an error message (typically when focus is left) if the result is invalid?
The first approach is "don't allow the user to do something you know is wrong" but has the disadvantage that it may not be at all obvious what is going on if a keyboard key is typed and nothing happens. It also breaks the expectation that, if you type something in a text field, you expect to see what you typed.
In the past, I've generally leaned towards the prevention approach but in general but feel perhaps, at the field input-level, the validation approach provides a better user experience. Is anyone aware of a best practice here?