Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Validator

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Hi,

I'm trying to use a regular expression validator, but I'm having a problem with my expression.

I have a multi-line textbox which should contain at least 10 but no more than 255 characters.

The expression I have is ^\w{10,255}

The error message is set to 'Content must be between 10 and 255 characters. Please edit'

The validator shows the message if I type more that 255 or less than 10. Great... but it will not show if I don't enter anything in the box. What do I need to change to the regex... or do I need an extra separate validator (RequiredFieldValidator)

I've not failed! Just found 100 ways that don't work...yet!
 
Actually further testing has shown my regex is inappropriate...

If I type 'This is a Test' then I get the error message as the regex stops at the space and thus the validation fails as that is less then 10 characters

If I type 'ThisisaTest' then the entry is accepted.

Any advice on a regex that will trigger if the text string is...
1. Not Blank (Can contain spaces but must not contain only spaces)
2. Must have at least 10 characters
3. Cannot be more than 255 characters

Note any AlphaNumeric plus space and these characters !"£$%^&*(){}[]@:;<>,.?/\~#¬`_-+=| are acceptable.

I've not failed! Just found 100 ways that don't work...yet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top