import re
import click


def validate_mfa_device_name(ctx, param, value):
    """Validates a virtual MFA device name."""
    try:
        if not all([re.match(r"[\w+=/:,.@-]+", value), 9 <= len(value) <= 256]):
            raise ValueError(value)
        return value
    except ValueError:
        click.echo('Invalid device name given, only ASCII characters and + = / : , . @ - are allowed with a length '
                   'between 9 and 256 with no spaces.')
        value = click.prompt(param.name)
        return validate_mfa_device_name(ctx, param, value)