Reputation: 1986
I am using vaadins builtin RegexpValidator to check for valid form fields.I have a description field that can have any charater as long as it's not empty.Initialy i was using ".+" which pretty much worked but when i converted that field from TextField to TextArea it didn't match my strings anymore as ".+" doesn't check for newlines or blank spaces.
I have tried doing "(.|\n|\r)+" but that includes writing a blank space or a newline aswell.
I need only to make sure that i have entered atleast one character it doesn't matter what. Normally with regex you can check for blanks with "^\s*$" but vaadins RegexpValidator result must match your string so what i am looking is basicaly the opposite of "^\s*$" ? but including atleast one character? RegexpValidator is really confusing me
Upvotes: 0
Views: 1956
Reputation: 93026
If you want to allow a pure whitespace text you can use
[\s\S]+
\s
a whitespace character
\S
a non whitespace character
that would match at least one character and would also match newlines, because they are included in \s
If you want to have at least one Non-whitespace character you can use
^\s*\S
That would check for 0 or more whitespaces at the start of the string (this would cover leading newlines) and it would be successful when it finds the first non whitespace.
Upvotes: 1