RegularExpressionValidator
The RegularExpressionValidator validate an input user control content based on a regular expression. Then, if you want have a string of length between 1 and 20 containing a single word (without blank spaces) you can add the following regular expression to the validator:
^\w{1,20}$
Unfortunately, this isn't sufficient. A note on MSDN library states:
Note Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.
I sincerly don't agree with that design decision since if the regular expression states that the string must be at least 1 character long, why should I have to use two validators ? The entropy of our code grows uselessly.
The only workaround I found on client side is to edit the function RegularExpressionValidatorEvaluateIsValid on WebUIValidation.js file. Just commenting the following lines of code:
if (ValidatorTrim(value).length == 0)
return true;
It seems to work now.