isStrongPassword method Null safety

bool? isStrongPassword()

Checks whether the String is a "strong" password which 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? isStrongPassword() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return false;
  }
  var regex = RegExp(
      r'^(?=.*([A-Z]){1,})(?=.*[!@#$&*]{1,})(?=.*[0-9]{1,})(?=.*[a-z]{1,}).{8,100}$');
  return regex.hasMatch(this!);
}