isPassword property
bool
get
isPassword
Checks if the string is a valid password.
A valid password must:
- Be at least 8 characters long.
- Contain at least one alphabetic character.
- Contain at least one digit.
- Contain at least one special character from the set
!@#\$%^&*=
(excluding spaces).
Example:
var password = 'P@ssw0rd';
print(password.isPassword); // Outputs: true
Returns true
if the string meets all password criteria, otherwise false
.
Implementation
bool get isPassword {
if (length < 8) {
return false;
}
RegExp alphaExp = RegExp(r'[a-zA-Z]');
RegExp digitExp = RegExp(r'\d');
RegExp specialExp = RegExp(r'[!@#\$%\^&\*=]');
if (!alphaExp.hasMatch(this) ||
!digitExp.hasMatch(this) ||
!specialExp.hasMatch(this)) {
return false;
}
return true;
}