PHP preg_match needed to ensure only ONE space character is allowed between words

后端 未结 3 1761
广开言路
广开言路 2020-12-11 23:47

basically I need a preg_match that ensures that only one space character is allowed between each word (IF there is more than one word).

My existing rule is:

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 00:11

    It depends what you mean by "word", but assuming you mean letters in A-Z or a-z you can try this:

    ^[a-zA-Z]+( [a-zA-Z]+)*$
    

    Note that \s does not mean the space character - it means any whitespace, including a new line.

提交回复
热议问题