Answers for "Password validation in dart with RegExp"

0

Password validation in dart with RegExp

bool isPasswordCompliant(String password, [int minLength = 8]) {
  if (password == null || password.length < minLength) {
    return false;
  }

  bool hasUppercase = password.contains(RegExp(r'[A-Z]'));
  if (hasUppercase) {
    bool hasDigits = password.contains(RegExp(r'[0-9]'));
    if (hasDigits) {
      bool hasLowercase = password.contains(RegExp(r'[a-z]'));
      if (hasLowercase) {
        bool hasSpecialCharacters = password.contains(RegExp(r'[!@#$%^&*(),.?":{}|<>]'));
        return hasSpecialCharacters;
      }
    }
  }

  return false;
}
Posted by: Guest on April-26-2021

Code answers related to "Password validation in dart with RegExp"

Browse Popular Code Answers by Language