phoneNumberValidations method
Performs validations on a phone number string based on provided parameters.
Returns an error message indicating any validation failures, or an empty string if the phone number passes all validations.
Parameters:
emptyMsg: The error message to return if the phone number is empty.minLengthMsg: The error message to return if the phone number is shorter than the minimum allowed length.maxLengthMsg: The error message to return if the phone number is longer than the maximum allowed length.
Example:
String error = phoneNumberValidations(
emptyMsg: 'Phone number cannot be empty',
minLengthMsg: 'Phone number must be at least 5 digits long',
maxLengthMsg: 'Phone number cannot exceed maximum length'
);
Note: This function internally uses other validation functions such as isEmpty, isMinLengthValid, and isMaxLengthValid.
Example:
String error = phoneNumberValidations(
emptyMsg: 'Phone number cannot be empty',
minLengthMsg: 'Phone number must be at least 5 digits long',
maxLengthMsg: 'Phone number cannot exceed maximum length'
);
Implementation
String phoneNumberValidations({
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)) {
error = minLengthMsg;
}
return error;
}