import re


def valid_account(name, allow_empty=False):
    """Returns validated account name or throws Assert."""
    if not name:
        assert allow_empty, 'invalid account (not specified)'
        return ""
    assert isinstance(name, str), "invalid account name type"
    assert 3 <= len(name) <= 16, "invalid account name length: `%s`" % name
    assert name[0] != '@', "invalid account name char `@`"
    assert re.match(r'^[a-z0-9-\.]+$', name), 'invalid account char'
    return name