This simple javascript will do the trick:

<TEXTAREA NAME="text" COLS=50 ROWS=10 class="form"
onKeyDown="LimitText(this.form.text);"
onKeyUp="LimitText(this.form.text);"></TEXTAREA>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function LimitText(field) {
if (field.value.length > 500){
 field.value = field.value.substring(0, 500);
 alert("Sorry, messages cannot be any longer than 500 characters.");
 }
}
// End -->
</script>
                                                 

-----Original Message-----
From: JRose [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 07, 2005 9:13 AM
To: RegEx
Subject: counting words in a textarea


greetings list,

I need to count the words in a textarea and validate client side that it

doesn't exceed a certain number.

We have been trying to use regular expressions to count the words.  Is 
there a way to count the words in a string and return the number of
words 
to test against this value.  We would then trim out the extra words and 
send them back to the form.

We have it working using indexOf and only checking for spaces, but run
into 
problems when there are tabs in the textarea.

thanks and kind regards,
Jeffrey




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:21:867
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/21
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:21
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.21
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to