Php 允许在此正则表达式中使用空格

Php 允许在此正则表达式中使用空格,php,regex,Php,Regex,我以前在用户名匹配中使用过这个正则表达式,但现在我希望能够允许空格。我该怎么做呢 if (!preg_match('/^[a-zA-Z0-9]+$/', $teamname)) { $errors[] = "Team name can only contain letters, numbers, and no spaces."; } 只需在中添加空格。您是指用户名前后的空格吗?或者在用户名中允许空格?e、 g.“我

我以前在用户名匹配中使用过这个正则表达式,但现在我希望能够允许空格。我该怎么做呢

            if (!preg_match('/^[a-zA-Z0-9]+$/', $teamname)) {
                $errors[] = "Team name can only contain letters, numbers, and no spaces.";
            }

只需在中添加空格。

您是指用户名前后的空格吗?或者在用户名中允许空格?e、 g.
“我最棒的用户名”
有效吗?或者你是说
“myawesomeusername”
(注意两边的空格)。可能的副本工作得很出色。非常感谢。
if (!preg_match('/^[a-zA-Z0-9 ]+$/', $teamname)) {
    $errors[] = "Team name can only contain letters, numbers, and spaces.";
}