When users register to my website I want to allow them to use spaces in their username, but only one space per word.
My current code:
$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.";
}
What do I need to add to ensure there is only one space entered inebtween words of the username?