def _validate_role_name(name):
    """Ensure a role has a valid name

    Raises InvalidNameError if role name is invalid
    """
    if not _role_name_pattern.match(name):
        raise InvalidNameError(
            f"Invalid role name: {name!r}."
            " Role names must:\n"
            " - be 3-255 characters\n"
            " - contain only lowercase ascii letters, numbers, and URL unreserved special characters '-.~_'\n"
            " - start with a letter\n"
            " - end with letter or number\n"
        )
    return True
Ensure a role has a valid name

Raises InvalidNameError if role name is invalid
jupyterhub/roles.py