testTextLine static method

String testTextLine(
  1. String text
)

Implementation

static String testTextLine(String text) {
  // remove white spaces on each line
  String res = text.replaceAll(' ', '');

  //
  List<String> list = res.split('');

  // to check if the text belongs to any MRZ format or not
  if (list.length != 44 && list.length != 30 && list.length != 36) {
    return '';
  }

  for (int i = 0; i < list.length; i++) {
    if (RegExp(r'^[A-Za-z0-9_.]+$').hasMatch(list[i])) {
      list[i] = list[i].toUpperCase();
      // to ensure that every letter is uppercase
    }
    if (double.tryParse(list[i]) == null &&
        !(RegExp(r'^[A-Za-z0-9_.]+$').hasMatch(list[i]))) {
      list[i] = '<';
      // sometimes < sign not recognized well
    }
  }
  String result = list.join('');
  return result;
}