import click
import re


def sanitize_user_name(ctx, param, value):
    """Check usernames for length and invalid characters.
    """
    del ctx
    del param

    if len(value) > 255:
        raise click.BadParameter('Username length > 255.')

    if not re.match(r'^[a-zA-Z0-9_\+=,\.@-]+$', value):
        raise click.BadParameter('Invalid characters in username')

    return value.lower()