2012-01-17 40 views
-1

我以前在我的用戶名匹配中使用了此正則表達式,但現在我希望能夠允許空格。我如何去做這件事?允許此正則表達式中的空格

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

你之前和名後,意味着空間?或允許用戶名內的空格?例如是我的真棒用戶名有效嗎?或者你的意思是''myawesomeusername''(注意兩邊的空格)。 –

+0

[Regex for names]的可能重複(http://stackoverflow.com/questions/275160/regex-for-names) – mario

回答

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

就在添加一個空格。

+0

出色地工作。謝謝! –

+0

不客氣! – Cyclone

相關問題