Avatar handle rules: 2 to 30 characters, with a Python check

A Sume avatar_handle allows a-z, 0-9, dot and underscore, 2 to 30 characters, no edge or doubled separators. A short Python check, plus the reserved prefix.

3 min readSume
All posts

The pattern

The API accepts handles that match this pattern: 2 to 30 characters, only lowercase a to z, digits 0 to 9, dot and underscore, with no dot or underscore at the start or end, and no two separators in a row. A leading @ is dropped, as the existing guide explains.

Examples against the pattern
HandlePasses?Why
product_hostYesLetters and one underscore
aNoUnder 2 characters
_mayaNoStarts with a separator
maya_NoEnds with a separator
maya..ugcNoTwo separators in a row
sume_hostPasses the patternFails later: reserved prefix, 409

Check before you pay

The same regex in Python, runnable as is:

import re
PATTERN = re.compile(r'^(?=.{2,30}$)(?![._])(?!.*[._]$)(?!.*[._]{2})[a-z0-9._]+$')
for h in ['product_host', 'a', '_maya', 'maya_', 'maya..ugc', 'x' * 31]:
    print(h[:12], bool(PATTERN.match(h)))

Two checks the pattern cannot make

The pattern knows nothing about the prefix or your other avatars. sume_ gives 409 avatar_handle_reserved, and a handle already in your workspace gives 409 avatar_handle_taken. Treat the regex as a first filter only.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume