Validate IBANs

This is how you validate an IBAN using the iban_util functions. Optionally you can restrict to CH and LI IBANs.

#include <iostream>

#include <qrinvoice/util/iban_util.hpp>

// ...

// When you use iban_util in order to validate IBAN numbers, you need to decide, whether the country code should be validated
// this is done using the 2nd parameter named "validate_country_code"
// if set to true, the country code should be validated. If so, only "CH" and "LI" IBANs are allowed
// (the only supported IBANs are CH and LI for the QR Bill)
// if set to false, IBANs are validated without restriction on the country code

// you can validate IBANs in normalized format
std::cout << qrinvoice::iban_util::is_valid_iban("CH3908704016075473007", true) << std::endl;
// prints 1 (true)

// or in formatted format, both is supported
std::cout << qrinvoice::iban_util::is_valid_iban("CH39 0870 4016 0754 7300 7", true) << std::endl;
std::cout << qrinvoice::iban_util::is_valid_iban("LI21 0881 0000 2324 013A A", true) << std::endl;
// prints 1 (true)

// the following two lines show how to validate IBAN from Germany, Belgium and Malta
std::cout << qrinvoice::iban_util::is_valid_iban("DE89 3704 0044 0532 0130 00", false) << std::endl;
std::cout << qrinvoice::iban_util::is_valid_iban("BE68844010370034", false) << std::endl;
std::cout << qrinvoice::iban_util::is_valid_iban("MT98MMEB44093000000009027293051", false) << std::endl;
// prints 1 (true)

Validate QR-IBANs

QR-IBAN validation is a specialization of IBAN validation, as it implicitly restricts country codes to CH and LI and checks, that the IID is withing the specified QR-IID range of 30000 – 31999.

#include <iostream>

#include <qrinvoice/util/iban_util.hpp>

// ...

std::cout << qrinvoice::iban_util::is_qr_iban("CH44 3199 9123 0008 8901 2") << std::endl;
// prints 1 (true)

std::cout << qrinvoice::iban_util::is_qr_iban("CH39 0870 4016 0754 7300 7") << std::endl;
// prints 0 (false)