//字母、数字(A-Z,a-z,0-9)、下划线以及最低5个字符,最大20个字符。 $username = "user_name12"; if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) { echo "Your username is ok."; } else { echo "Wrong username format."; }