I was reviewing the username validation logic and noticed the error message appears to be incorrect.
The error message states:
“Username invalid, no spaces or control characters allowed.”
However, the actual regex used for username validation is:
invalidUsernameRegex = regexp.MustCompilePOSIX("([[:cntrl:]]|[[\t\n\r\f\v]])+")
This pattern only blocks control characters and specific whitespace (\t\n\r\f\v), but not regular spaces (ASCII 32).
There’s a separate invalidCharsRegex that does block spaces via [[:space:]], which is used for other fields like custom IDs and device IDs. This suggests allowing spaces in usernames is intentional.
Relevant code:
Suggestion:
Update the error message to reflect what’s actually validated:
“Username invalid, no control characters allowed.”
This would reduce confusion for developers trying to understand what characters are permitted in usernames.
Hi @KamilDev,
Thanks for reporting.
It’s more likely that we’ll change the validation to also reject spaces chars in usernames instead of returning a different error.
Hi @sesposito,
Thanks for looking into this. However, I’d like to push back on changing the validation to reject spaces.
After digging deeper into the codebase, I found this in the CHANGELOG for version 3.5.0 (August 2021):
“Allow standard space characters in usernames for direct compatibility with Steam display names.”
This confirms that allowing spaces was an intentional, documented feature, not a bug. The separate invalidUsernameRegex variable was deliberately created to exclude spaces for this exact purpose. Steam display names commonly include spaces.
Concerns with changing this now:
-
Breaking change after 4+ years: This behavior has been in production since August 2021. Games built on Nakama have been allowing spaces in usernames for years.
-
Existing user data: Users already have usernames with spaces. Changing validation now creates inconsistency where existing usernames contain spaces but new ones can’t.
-
Steam compatibility regression: The feature was added specifically for Steam display names. Removing it breaks that integration.
It looks like when the logic was updated to allow spaces, the error messages were never updated to reflect the change. Updating the error messages to match the actual logic seems like the correct fix here.
Good finding @KamilDev, we’ll have a discussion internally on which way to proceed and will let you know.