passwordValidations method
Performs validations on a password string based on provided parameters.
Returns an error message indicating any validation failures, or an empty string if the password passes all validations.
Parameters:
emptyMsg: The error message to return if the password is empty.minLengthMsg: The error message to return if the password is shorter than the minimum allowed length.maxLengthMsg: The error message to return if the password is longer than the maximum allowed length.
Example:
String error = passwordValidations(
emptyMsg: 'Password cannot be empty',
minLengthMsg: 'Password must be at least 6 characters long',
maxLengthMsg: 'Password cannot exceed 12 characters'
);
Note: This function internally uses other validation functions such as isEmpty, isMinLengthValid, and isMaxLengthValid.
Example:
String error = passwordValidations(
emptyMsg: 'Password cannot be empty',
minLengthMsg: 'Password must be at least 6 characters long',
maxLengthMsg: 'Password cannot exceed 12 characters'
);
Implementation
String passwordValidations({
int? min,
int? max,
required String emptyMsg,
required String minLengthMsg,
required String maxLengthMsg,
}) {
String error = "";
NexValidationsFunctions functions = NexValidationsFunctions();
if (functions.isEmpty(this)) {
error = emptyMsg;
} else if (functions.isMinLengthValid(this, min: min)) {
error = minLengthMsg;
} else if (functions.isMaxLengthValid(this, max: max)) {
error = minLengthMsg;
}
return error;
}