$pattern = '/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{5,20}$/'; if(!preg_match($pattern,$username)){ return $this->error('用户名只能是数字加字母组合'); }