Regularexpression validator on multiline text box

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
S

Stephan Bour

Follow up to previous question:
I¹m trying to validate a multipline asp text box that can have a maximum of
150 word characters but any number of white space, carriage returns or tabs.
I tried several regex that pass testing on regexplib.com but fail on the
page
This for example doesn¹t work properly:

ValidationExpression="^\w{1,150}|\s{0,}$"

I get a validation error if any non-word character is added, regardless of
the total length of the string.

I think I'm having a problem because the text box is multiline and the regex
doesn't check it as single line. I have solved that problem before by using
RegexOptions.Singleline in the code behind file but I don't know how to do
that within the asp RegularExpressionValidator tag.
Any idea?
Thanks,
Stephan.
 
Stephan,

You'll need to allow white space characters before, between, and after your
word characters. Try this instead:

^\s*(\w\s*){1,150}\s*$

HTH,
Nicole
 
Back
Top