You could consider doing it without regex:
$len = strlen($username);
if ($len > 5 && $len < 21 && ctype_alnum($username)) {
// username is valid
} else {
// username is invalid
}
But if you insist, what you were missing are the assertions for the start and end of subject:
if (preg_match('/^[a-z0-1]{6,20}$/i', $username)) {
// username is valid
} else {
// username is invalid
}