The two possible methods of input into the text box - typing or pasting, lead to different possible responses by the document. Typing allows you to evaluate individual keystrokes while pasting requires that the focus on the text field changes to trigger the handler.

I have tried to avoid these differences by installing a Go button. This does nothing more than force a change in focus when you click it. I have used javascript and a form containing the various elements to extract and compare values, and finally, to truncate the string as required. The limit shown can be set at any value of string length.