Future fix Mention autocomplete doesn't work in some cases where the username contains an '@' character

Affected version


Well-known member
Consider the username M@tze. You can mention him in a post by typing @M@tze. This works fine.

But the autocomplete doesn't work: No suggestions are shown after you type an @ character followed by the first two characters: @M@.

The problem seems to be that XenForo only looks at the part of the username following the last @ character:
var lastAt = text.lastIndexOf(this.options.at);


XenForo developer
Staff member
FWIW, this was the code behind that, replacing everything from var lastAt = text.lastIndexOf(this.options.at); up until the final return null;

            var m = text.match(new RegExp('(^|\\s|[\\](,]|--)' + this.options.at + '([^,\\n]{1,14})$'));
            if (m)
                var afterAt = m[2];

                if (!afterAt.match(/\s/) || afterAt.length <= 15)
                    return {
                        text: text,
                        textNode: textNode,
                        start: text.length - afterAt.length - 1,
                        query: afterAt.replace(new RegExp(String.fromCharCode(160), 'g'), ' '),
                        range: selection


Well-known member
@Kier what Discord does is start the user mentions with an @ but write the selected user mention as @example#userid into the text rather than just @example

This approach would better handle usernames which overlap, and remove the need for complex selection logic in the php-side which requires the auto-complete logic and username lookup to exactly match.

And also fix crazy stuff like; [ICODE]@Username[/ICODE] being rendered as [ICODE][USER=58777]@Username[/USER][/ICODE]. Especially if you check username is owned by the user id with the @example#userid format