Possible Duplicate:
Regular Expressions: low-caps, dots, zero spaces
How could I change the regular expression below to only allow lower-case letters?
function valid_username($username, $minlength = 3, $maxlength = 30)
{
$username = trim($username);
if (empty($username))
{
return false; // it was empty
}
if (strlen($username) > $maxlength)
{
return false; // to long
}
if (strlen($username) < $minlength)
{
return false; //toshort
}
$result = ereg("^[A-Za-z0-9_\-]+$", $username); //only A-Z, a-z and 0-9 are allowed
if ($result)
{
return true; // ok no invalid chars
} else
{
return false; //invalid chars found
}
return false;
}
You have both A-Z and a-z in your character class, just omit the A-Z to only allow for the a-z (lowercase) letters. I.e.