isGreekId property

bool isGreekId

Checks whether the provided String is a valid Greek ID number.

The number should be of format XX999999, where XX are letters from both the Greek and the Latin alphabet (ABEZHIKMNOPTYX).

Example

String foo = 'AB123456';
bool isGreekId = foo.isGreekId; // returns true;
String foo = 'AB1234567';
bool isGreekId = foo.isGreekId; // returns false;

Implementation

bool get isGreekId {
  if (this.isBlank) {
    return false;
  }

  if (this.length != 8) {
    return false;
  }

  final List<String> firstTwoLetters = this.first(n: 2).split('');
  final String restLetters = this.last(n: 6);

  // Besides the first two letters, the rest of the ID should be a 6digit number.
  if (!restLetters.isNumber) {
    return false;
  }

  // If the first two letters of the provided String are not valid ones.
  if (!StringHelpers.validLetters.contains(firstTwoLetters.first) ||
      !StringHelpers.validLetters.contains(firstTwoLetters.last)) {
    return false;
  }

  return true;
}