Regular expression that allows spaces in a string, but not only blank spaces

后端 未结 6 2086
长发绾君心
长发绾君心 2020-12-01 18:31

I need to write a regular expression for form validation that allows spaces within a string, but doesn\'t allow only white space.

For example - \'Chicago Heigh

6条回答
  •  -上瘾入骨i
    2020-12-01 18:58

    It's very simple: .*\S.*

    This requires one non-space character, at any place. The regular expression syntax is for Perl 5 compatible regular expressions, if you have another language, the syntax may differ a bit.

提交回复
热议问题