When creating a new user with core_users_create_user, how do I check the username policy that is defined in Moodle security config to make sure the username will comply?
Thanks
To answer my own question, I figured out that there is no username policy specified in config (only password policy).
The default behavior for Moodle username is: Moodle username policy only allows alphanumeric lowercase characters (letters/numbers) and underscore ( _ ) and hyphen( - ) and period( . ) and at-symbol( @ )
So using preg_replace you can eliminate everything that should not be there with this:
$username = strtolower($username); //convert any UPPERCASE to lowercase
$username = preg_replace('/[^-.@_0-9a-z]/', '', $username); //remove all other characters that are not allowed
Hi Jeff, do you know if there is a way to display the username policy on the signup page, just as the password policy is displayed (see attached pic)? Thanks.