The following example shows how to use the CountryUtils class in order to validate the country code of addresses.

import ch.codeblock.qrinvoice.util.CountryUtils;

// ...

// just a few examples of valid ISO 3166-1 alpha-2 country codes
System.out.println(CountryUtils.isValidIsoCode("CH"));
System.out.println(CountryUtils.isValidIsoCode("LI"));
System.out.println(CountryUtils.isValidIsoCode("DE"));
// prints true

// Codes must be in upper case
System.out.println(CountryUtils.isValidIsoCode("ch"));
// thus this prints false