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.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>max string length</title>
<style type="text/css">
body { font-family:arial, helvetica, sans-serif; font-weight:normal; font-size:13px; color:#000; text-align:left; margin:3px 0px; }
input { margin-right:10px; text-align:center; }
#wrap { width:600px; height:500px; margin:20px; overflow:auto; }
.lftF { float:left; margin-right:20px; }
#holder { overflow:auto; }
#holder input { text-align:center; }
</style>
</head>
<body>
<div id="wrap">
<form name="f2">
<p>
<input type="text" value="nondum amabam, et amare amabam, et secretiore indigentia oderam me minus" name="T1" size="70"><input type="button" onclick="getLength()" value="Go" name="B2"></p>
<p><b>Limit:</b> <input type="text" value="50" name="limitT" size="10">
<b>Original</b>
<input type="text" value="72" name="actualT" size="10" readonly></p>
<p><input type="reset" value="Reset" name="B2"></p>
</form>
</div>
<!-- end wrap -->
<script type="text/javascript">
function getLength()
{ var df2=document.f2;
var limitLength=df2.limitT.value;
var actualLength=df2.T1.value.length;
df2.actualT.value=actualLength;
// crop it
if(limitLength<=actualLength)
{ df2.T1.value=df2.T1.value.substr(0,limitLength); }
}
</script>
</body>
</html>