Right; and how far have you got so far? (I recommend not trying to do all this in one regular expression. For example, part 5 can be done as strpos('__',$user)===false, part 4 as $user[strlen($user)-1]!='_', and part 3 as preg_match('/[a-z0-9]$/i', $user)).