全名字段中的空格验证


Space validation in full name field

我想在全名字段中检查全名字段是否应该接受名字和姓氏之间的空格,因为我正在使用strrpos()函数,但不能使用

您可以使用正则表达式。。。

if (preg_match("/(.+)( )(.+)/", $full_name))
{ 
// returns true if name is formed of two words with a space between
}

为了更好地验证,您可以使用''w,但请记住它只匹配英语单词字符。请参阅此处了解更多信息:为什么''w在javascript正则表达式中只匹配英文单词?

preg_match("/('w+)( )('w+)/", $full_name)