【发布时间】:2014-03-29 17:11:19
【问题描述】:
当用户注册到我的网站时,我希望允许他们在用户名中使用空格,但每个单词只能使用一个空格。
我当前的代码:
$usor = $_POST['usernameone'];
$allowed = "/[^a-z0-9 ]/i";
$username = preg_replace($allowed,"",$usor);
$firstlettercheck = $username[0];
$lastlettercheck = substr("$username", -1);
if ($firstlettercheck == " " or $lastlettercheck == " ")
{
echo "Usernames can not contain a space at start/end of username.";
}
我需要添加什么以确保在用户名的单词之间只输入一个空格?
【问题讨论】:
-
您应该选择警告用户和执行自动更正。
标签: php string replace preg-replace space