import click


def cb_validate_address(ctx, param, value):
    """Validate hex address parameter."""
    try:
        if value is not None:
            address = int(value, 16)
            if address not in range(0, 0x10000):
                raise click.BadParameter(
                    'address must be between 0x0000 and 0xFFFF')
            return address
    except ValueError as address_error:
        raise click.BadParameter(
            'address must be hex value') from address_error