isStrongPassword property

bool get isStrongPassword

Checks whether the String complies to below rules :

  • At least 1 uppercase
  • At least 1 special character
  • At least 1 number
  • At least 8 characters in length

Example

String foo = 'qwerty';
bool isStrong = foo.isStrongPassword; // returns false
String foo = 'IsTh!$Strong';
bool isStrong = foo.isStrongPassword; // returns true

Implementation

bool get isStrongPassword {
  if (isBlank) {
    return false;
  }
  var regex = RegExp(r'^(?=.*([A-Z]){1,})(?=.*[!@#$&*,;.?]{1,})(?=.*[0-9]{1,})(?=.*[a-z]{1,}).{8,100}$');
  return regex.hasMatch(this);
}