开发者

Regular Expression regex to validate input: Two words with a space between

i need to use a regular expression to validate a field with php that has to have two words separated by a space like: "First开发者_如何学运维 Last" but i cant find one that fits my purposes, can anyone help me?

The best i've done is ^[a-zA-Z0-9_\s]*$ but with this i can have more than one space and anywhere in the field and i want only between the words. Can anyone help me?


Something like ^\w+\s\w+$ ought to work for this case. But you don't necessarily need to use regular expressions for this, you could just use explode().


^[^\s]+\s[^\s]+$
  • [^\s]+ matches one or more characters, except whitespace characters;
  • \s matches a single whitespace character.


This might do the trick

^[a-zA-Z0-9]+ {1}[a-zA-Z0-9]+$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜