-1
我以前在我的用户名匹配中使用了此正则表达式,但现在我希望能够允许空格。我如何去做这件事?允许此正则表达式中的空格
if (!preg_match('/^[a-zA-Z0-9]+$/', $teamname)) {
$errors[] = "Team name can only contain letters, numbers, and no spaces.";
}
我以前在我的用户名匹配中使用了此正则表达式,但现在我希望能够允许空格。我如何去做这件事?允许此正则表达式中的空格
if (!preg_match('/^[a-zA-Z0-9]+$/', $teamname)) {
$errors[] = "Team name can only contain letters, numbers, and no spaces.";
}
if (!preg_match('/^[a-zA-Z0-9 ]+$/', $teamname)) {
$errors[] = "Team name can only contain letters, numbers, and spaces.";
}
就在添加一个空格。
出色地工作。谢谢! –
不客气! – Cyclone
你之前和名后,意味着空间?或允许用户名内的空格?例如是我的真棒用户名有效吗?或者你的意思是''myawesomeusername''(注意两边的空格)。 –
[Regex for names]的可能重复(http://stackoverflow.com/questions/275160/regex-for-names) – mario