isPassword method

bool isPassword(
  1. String password
)

Validates if the given password meets the required criteria.

The password must be at least 8 characters long and include at least one uppercase letter, one lowercase letter, one digit, and one special character. Returns true if the password is valid, otherwise false.

Implementation

bool isPassword(String password) {
  String pattern =
    r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$';
  RegExp regExp = RegExp(pattern);
  return regExp.hasMatch(password);
}