Forum Moderators: coopster
$username = 'testuser%1';
if (preg_match('/^([\w]*%[\w]*)$/i', $username))
{
echo 'has percentage';
}
That checks for a percentage sign anywhere in the string. Is that what you were trying to achieve?
$hasPercent = strpos('%', $username);
if ($hasPercent!== false)
{
echo 'has percentage character';
}
strpos is much faster that using a regular expression and easier to read... it just depends if there are other factors you need to test for in the same username (has to have a certain number of words etc.)