passwordValidator static method

String? passwordValidator(
  1. String? value, [
  2. String? errorMessage
])

passwordValidator to validate whether a password is strong or not

validator: (value) => SimpleValidations.passwordValidator(value, [errorMessage]),

Implementation

static String? passwordValidator(String? value, [String? errorMessage]) {
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (value.length < 8) {
    return errorMessage ?? 'Password must be at least 8 characters long';
  } else if (!value.contains(CustomRegEx.passwordRegex[0])) {
    return errorMessage ??
        'Password must contain at least one uppercase letter';
  } else if (!value.contains(CustomRegEx.passwordRegex[1])) {
    return errorMessage ??
        'Password must contain at least one lowercase letter';
  } else if (!value.contains(CustomRegEx.passwordRegex[2])) {
    return errorMessage ?? 'Password must contain at least one digit';
  }
  return null;
}