isPasswordValid static method
String?
isPasswordValid(
- String password, {
- String? message,
- String? passwordLFormatMessage,
- int? passwordLength = 8,
- String? passwordValidationMessage = "Please enter valid password",
- String? passwordLengthValidationMessage = "Password should be at least 8 characters",
})
Implementation
static String? isPasswordValid(String password,
{String? message,String? passwordLFormatMessage,int? passwordLength=8,
String? passwordValidationMessage="Please enter valid password",
String? passwordLengthValidationMessage="Password should be at least 8 characters"}) {
if(password.isEmpty){
return passwordValidationMessage;
}else if (password.length < passwordLength!) {
return message??passwordLengthValidationMessage;
}else if (!RegExp(
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$')
.hasMatch(password)) {
return passwordLFormatMessage??"Password should contain at least one uppercase letter, one lowercase letter, one number and one special character";
}
return null;
}