Friday, January 8, 2010

ASp.NET Multiline textBox limiting number of characters

In .Net you can not limit the size of the multiline text box with MaxLength property. The multiline text box with MaxLength property does not work. To do the validation you can add regular expression validation control & you can set the expression to
ValidationExpression="^([\S\s]{0,2500})$"
This will limit the number of character to 2500.
You can have summary validation control to summarize all the validation errors.

If you want to block entry into text box you can do with javascript:

onkeypress="if(this.value.length>=2500) return false;"

But people can paste larger text & then it will not be editable.