isValidBBAN function

bool isValidBBAN(
  1. String? bban,
  2. String countryCode
)

Validate BBAN

// returns `true`
ibantools.isValidBBAN("ABNA0417164300", "NL");
// returns `false`
ibantools.isValidBBAN("A7NA0517164300", "NL");

Implementation

bool isValidBBAN(String? bban, String countryCode) {
  if (bban == null || bban.isEmpty || countryCode.isEmpty) {
    return false;
  }

  final CountrySpec? spec = countrySpecs[countryCode];

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

  if (spec.chars! - 4 == bban.length &&
      _checkFormatBBAN(bban, spec.bbanRegexp!)) {
    if (spec.bbanValidationFunc != null) {
      return spec.bbanValidationFunc!(bban.replaceAll(RegExp(r'[\s.]+'), ''));
    }
    return true;
  }

  return false;
}