faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 11 people (45%) answered Yes
Recently 5 of 10 people (50%) answered Yes

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.