Need a Regular expresssion that should not allow only space in string, It can allow spaces along with characters
Need a Regular expresssion that should not allow only space in str开发者_开发百科ing, It can allow spaces along with characters.
e.g: space+char+space is allowed where as only space is not allowed
/\S/
is sufficient to match a non-empty string.
Try this:
/^\s+$\
Any string that matches the above expression is invalid as per your criteria.
Maybe it's easier and faster to test the emptiness of the string after using trim() on it.
If you're just looking for a positive match:
/\S/
If you want to capture:
/(.*\S.*)/
EDIT:
Actually, if you meant a literal space:
/[ ]/
You simply have to enforce a non-space character appearing at least once:
\s*\S+\s*
精彩评论