isPasswordValid
Validates if this string meets password complexity requirements.
Current Requirements
At least one digit (0-9)
At least one lowercase letter (a-z)
Length between 8 and 20 characters
Note: Adjust the regex pattern if you need different requirements (uppercase, special chars, etc.).
Usage Examples
// In a ViewModel - validate password on signup
fun validatePassword(password: String): PasswordValidation {
return when {
password.isEmpty() -> PasswordValidation.Empty
!password.isPasswordValid() -> PasswordValidation.Weak
else -> PasswordValidation.Valid
}
}
// In a Composable - show password strength
var password by remember { mutableStateOf("") }
val isValid = password.isPasswordValid()
OutlinedTextField(
value = password,
onValueChange = { password = it },
isError = password.isNotEmpty() && !isValid,
supportingText = {
if (password.isNotEmpty() && !isValid) {
Text("Password must be 8-20 chars with a digit and lowercase letter")
}
}
)Content copied to clipboard
Valid Examples
"password1" → true (8+ chars, has digit and lowercase)
"myp4ssword" → true
"test1234567890" → true
Invalid Examples
null → false
"" → false
"short1" → false (< 8 chars)
"password" → false (no digit)
"12345678" → false (no lowercase letter)
"verylongpasswordwithmorethan20characters1" → false (> 20 chars)
Receiver
String? The password string to validate (can be null).
Return
true if the password meets complexity requirements, false otherwise.