isValidIBAN function

bool isValidIBAN(
  1. String iban, {
  2. ValidateIBANOptions options = const ValidateIBANOptions(),
})

Validate IBAN

returns `true`
ibantools.isValidIBAN("NL91ABNA0417164300");
returns `false`
ibantools.isValidIBAN("NL92ABNA0517164300");
returns `true`
ibantools.isValidIBAN('CH4431999123000889012');
// returns `false`
ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });

Implementation

bool isValidIBAN(String iban,
    {ValidateIBANOptions options = const ValidateIBANOptions()}) {
  if (iban.isEmpty) {
    return false;
  }

  final RegExp reg = RegExp(r'^[0-9]{2}$');
  final String countryCode = iban.substring(0, 2);
  final CountrySpec? spec = countrySpecs[countryCode];

  if (spec == null || spec.bbanRegexp == null || spec.chars == null) {
    return false;
  }

  return (spec.chars == iban.length &&
      reg.hasMatch(iban.substring(2, 4)) &&
      isValidBBAN(iban.substring(4), countryCode) &&
      isValidIBANChecksum(iban) &&
      (options.allowQRIBAN || !isQRIBAN(iban)));
}