validate method
return error message if input is not valid given the current mode
otherwise return null, emphasising that there was no problem with the input
Implementation
String? validate(String? input,
[String emptyInputErrorMessage = 'Please enter a value here',
String generalError = 'The value provided is not correct']) {
if (input == null || input.isEmpty) {
return emptyInputErrorMessage;
}
String? message;
switch (mode) {
case InputValidationMode.email:
message = _emailRegex.hasMatch(input) ? null : generalError;
break;
case InputValidationMode.number:
message = _numberRegex.hasMatch(input) ? null : generalError;
break;
case InputValidationMode.name:
message = _nameRegex.hasMatch(input) ? null : generalError;
break;
}
return message;
}