tags:

views:

30

answers:

1

I have a textbox with a RegularExpressionValidator. I want to require the user to enter at least n characters. I'd also like to remove whitespace both at the start and end of the textbox. I'd still like to allow spaces within the textbox, I just want to remove the excess at the beginning and end.

I basically don't know how to combine the trim regex and the count together for use in a REV.

trim: ^\s*((?:[\S\s]*\S)?)\s*$
count: .{10}.*

I basically want to know if the input, after leading and trailing whitespace is removed, is greater than n characters.

A: 

You could use word boundaries to ignore the whitespace in the beginning, accept 10 characters, then end with another word boundary with a pattern like this:

\b.{10}\b

Be sure to also use a RequiredFieldValidator to cover empty inputs since the RegularExpressionValidator does not handle such cases.

Ahmad Mageed
Thanks. Simple but effective.
Shawn