call method
Validates whether a numeric value falls within the specified range.
This method checks if the input value is a valid numeric representation and
whether it falls within the specified range [min, max]. If the value is
outside the range or not a valid number, an error message is generated using
the buildMessage method.
Parameters:
attribute: The identifier of the form attribute being validated.value: The value to be validated.
Returns:
A validation error message if the value is outside the specified range or
not a valid number, or null if the value is valid.
Implementation
@override
String? call(String attribute, String value) {
if (value.isNotEmpty) {
final parsedValue = num.tryParse(value);
if (parsedValue == null ||
!((parsedValue >= min) && (parsedValue <= max))) {
return buildMessage(attribute, value, onExtra: (message) {
message = message.replaceAll(":min", min.toString());
message = message.replaceAll(":max", max.toString());
return message;
});
}
}
return null;
}