The way I solved this problem was to make a new class that extends mx.validators.StringValidator and adds the following properties:
- maxWords - the maximum number of words allowed
- minWords - the minimum number of words allowed
- tooManyWordsError - the error string to be displayed when too many words are entered
- tooFewWordsError - the error string when not enough words are entered
- trim - trims the input string before the validation occurs
Here is the utility function I wrote for counting how many words are in a string:
And here is it in action (view source). The validator will run when the TextArea loses focus (that is the default behavior), so try typing in one word and then pressing tab. You can also adjust the minimum and maximum number of words allowed and the validation will be updated immediately.
I also included the ResizableTextArea class too just for fun.