Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个正则表达式,它只允许字母和一些字符 (.-) 和空格。问题是即使文本字段为空,我也希望它通过。\s 需要一个空格,这很好,但我也希望它在没有任何键盘输入的情况下通过。这里是:
^[\sA-Za-z.-]+$
+将量词更改为*,您就完成了:-
+
*
^[\sA-Za-z.-]*$
它将匹配0 or more事件。并且0出现将意味着空字符串。
0 or more
0
我认为应该是 *(0 或更多)而不是 +(1 或更多)