isValid method

bool isValid(
  1. String? passport
)

function to check if the provided passport is valid or not.

returns true of the passport number seems valid.

Implementation

bool isValid(String? passport) {
  if (passport == null) return false;

  // remove the spaces from passport
  passport = passport.replaceAll(RegExp(r"\s+"), "");

  if (passport.length != 8) {
    // passport number length must be 8
    return false;
  }

  RegExp passportRegEx = RegExp(r"^[A-PR-WYa-pr-wy][1-9][0-9][0-9]{4}[1-9]$");
  return passportRegEx.hasMatch(passport);
}