Entry
How do I prevent a user from pasting more then "n" characters of text into a textarea
Dec 28th, 2005 04:02
b w, Simon Wine,
You can't. But you can immediately truncate whatever was pasted to legal
length. This limits the content to 300 characters:
<textarea rows="12" cols="80"
onKeyPress="this.value=String(this.value).slice(0,300);"
onBlur="this.value=String(this.value).slice(0,300);"
name="content"></textarea>
the onBlur piece is needed to avoid smartass users who would try to
paste more text using the context menu.