if you look in Githhub there is some code you can use do restrict spaces
strangerstudios/paid-memberships-pro
or there is this code that Might help
// Restrict username registration to alphanumerics
function limit_username_alphanumerics ($continue_registration) {
global $username;
if (! preg_match('/^[A-Za-z0-9]{3,16}$/', $username) ){
pmpro_setMessage(__("Username can only contain alphanumerics (A-Z 0-9)", "pmpro"), "pmpro_error");
$pmpro_error_fields[] = "username";
$continue_registration = false;
}
return $continue_registration;
}
add_filter('pmpro_registration_checks', 'limit_username_alphanumerics');