validateString static method

bool validateString(
  1. String string, {
  2. int minLength = 8,
  3. int maxLength = 20,
  4. bool firstCapital = false,
  5. bool firstDigit = false,
  6. bool includeDigit = false,
  7. bool includeAlphabet = false,
  8. bool includeSpecialCharacter = false,
  9. List<String>? includeCharacters,
  10. List<String>? ignoreCharacters,
  11. int minAlphabet = 5,
  12. int maxAlphabet = 20,
  13. int minDigit = 0,
  14. int maxDigit = 20,
})

Implementation

static bool validateString(String string, {
  int minLength = 8,
  int maxLength = 20,
  bool firstCapital = false,
  bool firstDigit = false,
  bool includeDigit = false,
  bool includeAlphabet = false,
  bool includeSpecialCharacter = false,
  List<String>? includeCharacters,
  List<String>? ignoreCharacters,
  int minAlphabet = 5,
  int maxAlphabet = 20,
  int minDigit = 0,
  int maxDigit = 20,
}) {
  if (string.length < minLength) {
    return false;
  }

  if (string.length > maxLength) {
    return false;
  }

  if (firstCapital && !isFirstCapital(string)) {
    return false;
  }

  if (firstDigit && !isFirstLetter(string)) {
    return false;
  }

  if (includeAlphabet && !isAlphabetIncluded(string)) {
    return false;
  }

  if (includeDigit && !isDigitIncluded(string)) {
    return false;
  }

  if (includeSpecialCharacter && !isSpecialCharacterIncluded(string)) {
    return false;
  }

  if (!isIncludedCharactersPresent(string, includeCharacters)) {
    return false;
  }

  if (isIgnoreCharactersPresent(string, ignoreCharacters)) {
    return false;
  }

  if (!checkMaxAlphabet(string, maxAlphabet)) {
    return false;
  }

  if (!checkMinAlphabet(string, minAlphabet)) {
    return false;
  }

  if (!checkMaxDigit(string, maxAlphabet)) {
    return false;
  }

  if (!checkMinDigit(string, minAlphabet)) {
    return false;
  }

  return true;
}