使用由发布的正则表达式Moaz (并增加资本),我们需要加入registration_errors
过滤器:
// Restrict username registration to alphanumerics
add_filter(\'registration_errors\', \'limit_username_alphanumerics\', 10, 3);
function limit_username_alphanumerics ($errors, $name) {
if ( ! preg_match(\'/^[A-Za-z0-9]{3,16}$/\', $name) ){
$errors->add( \'user_name\', __(\'<strong>ERROR</strong>: Username can only contain alphanumerics (A-Z 0-9)\',\'CCooper\') );
}
return $errors;
}