Printable Basic Bank Account Number (BBAN) for the given country code. The
    ``country`` must be a valid ISO 3166-2 country code.

    :param value: string or int
    :param country: string

    >>> bban('068-9999995-01', 'BE')
    '068999999501'
    >>> bban('555', 'NL')
    '555'
    >>> bban('555', 'NL', validate=True)
    Traceback (most recent call last):
        ...
    ValueError: Invalid BBAN, number does not match specification
    >>> bban('123', 'XY', validate=True)
    Traceback (most recent call last):
        ...
    ValueError: Invalid BBAN, country unknown

def bban(value, country=None, validate=False):
    '''
    Printable Basic Bank Account Number (BBAN) for the given country code. The
    ``country`` must be a valid ISO 3166-2 country code.

    :param value: string or int
    :param country: string

    >>> bban('068-9999995-01', 'BE')
    '068999999501'
    >>> bban('555', 'NL')
    '555'
    >>> bban('555', 'NL', validate=True)
    Traceback (most recent call last):
        ...
    ValueError: Invalid BBAN, number does not match specification
    >>> bban('123', 'XY', validate=True)
    Traceback (most recent call last):
        ...
    ValueError: Invalid BBAN, country unknown
    '''

    value = bban_compact(value)

    if validate:
        country = country.upper()

        try:
            rules = BBAN_RULES[country]
        except KeyError:
            raise ValueError(_('Invalid BBAN, country unknown'))

        regex = _bban_regex(rules['bban'])
        if not regex.match(value):
            raise ValueError(
                _('Invalid BBAN, number does not match specification')
            )

    return value