extractIBAN function
extractIBAN
// returns `ExtractIBANResult(iban: "NL91ABNA0417164300", bban: "ABNA0417164300", countryCode: "NL", valid: true, accountNumber: '0417164300', bankIdentifier: 'ABNA')`
ibantools.extractIBAN("NL91 ABNA 0417 1643 00");
Implementation
ExtractIBANResult extractIBAN(String iban) {
ExtractIBANResult result = ExtractIBANResult(iban: iban);
final String? eFormatIBAN = electronicFormatIBAN(iban);
result = result.copyWith(iban: eFormatIBAN ?? iban);
if (eFormatIBAN != null && isValidIBAN(eFormatIBAN)) {
result = result.copyWith(
bban: eFormatIBAN.substring(4),
countryCode: eFormatIBAN.substring(0, 2),
valid: true);
final CountrySpec? spec = countrySpecs[result.countryCode];
if (spec?.accountIdentifier != null) {
final List<String> ac = spec!.accountIdentifier!.split('-');
final int starting = int.parse(ac[0]);
final int ending = int.parse(ac[1]);
result = result.copyWith(
accountNumber: result.iban.substring(starting, ending + 1));
}
if (spec?.bankIdentifier != null) {
final List<String> ac = spec!.bankIdentifier!.split('-');
final int starting = int.parse(ac[0]);
final int ending = int.parse(ac[1]);
result = result.copyWith(
bankIdentifier: result.bban!.substring(starting, ending + 1));
}
if (spec?.branchIdentifier != null) {
final List<String> ac = spec!.branchIdentifier!.split('-');
final int starting = int.parse(ac[0]);
final int ending = int.parse(ac[1]);
result = result.copyWith(
branchIdentifier: result.bban!.substring(starting, ending + 1));
}
} else {
result = result.copyWith(valid: false);
}
return result;
}