XF 2.2 Preventing illegal characters in username

Orit

Active member
Hello
Quite a few of our users are recently changing their usernames to usernames containing emojis and other unicode characters.
Is there a way to prevent that?

I don't really mind them using those characters, but we get server errors regarding those changes:
XF\Db\Exception: MySQL query error [1267]: Illegal mix of collations (utf8mb3_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='src/XF/Db/AbstractStatement.php:230

Thanks!

Edit:
I found @AndyB suggestion to use regex. The problem is our board is not in English and we allow other language characters. I can't seem to generate a correct regex containing them too...

If you would like to only allow modern English alphabet, numbers and space in usernames, you can use the "Username match regular expression" field in the admin control panel:

Admin control panel -> Setup -> Options -> User registration

View attachment 263326

Enter the following:

/^[a-z0-9 ]+$/i
 
The problem is our board is not in English and we allow other language characters. I can't seem to generate a correct regex containing them too...
Regex was primarily developed for english, but can still be utilised with other languages. Depends on what language(s) though you want to support? [\p{L}] appears to be applicable for allowing all letters (not digits) in all/most languages? My site is english though, so I don't use or have tested this.
 
Back
Top Bottom