isShebaValid static method

bool isShebaValid(
  1. String sheba
)

Validates Iranian IBAN (Sheba) number @param sheba The IBAN number @returns bool True if valid Example: PersianTools.isShebaValid("IR123456789012345678901234") => true

Implementation

static bool isShebaValid(String sheba) {
  if (sheba.length != 26 || !RegExp(r"IR[0-9]{24}").hasMatch(sheba)) return false;
  final int d1 = sheba.codeUnitAt(0) - 65 + 10;
  final int d2 = sheba.codeUnitAt(1) - 65 + 10;
  final String iban = "${sheba.substring(4)}$d1$d2${sheba.substring(2, 4)}";
  String remainder = iban;
  while (remainder.length > 2) {
    final String block = remainder.length >= 9 ? remainder.substring(0, 9) : remainder;
    remainder = "${int.parse(block) % 97}${remainder.substring(block.length)}";
  }
  return int.parse(remainder) % 97 == 1;
}