Limiting size of Multi-line text box

P

paul reed

Hello,

I have a multi-line text box. The MaxLength property only works for
single-line text boxes. What are my options to limit the number of
characters entered to let's say 180? I can of course check the length on
postback I guess. I could also use jscript on the client?

What is the preferred approach?

Paul
 
S

Sink

You could us a validator control.
Probably a RegularExpressionValidator with
EnableClientScript = true,
ControlToValidate = <your textbox control>

this would automatically create a javascript
routine to check the clientside and another check on the
server side, be sure to check Page.IsValid on the server
side.

Both are really necessary 'cause it is rather easy to
work around clientside javascript for a hacker.

Example Regular expression:

^[^<>]{5,180}

This would check for script injection and set min length
to 5 and max length to 180.
Regards
Sink
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top