age static method
🎂 Age Validator (must be number and within range)
Implementation
static String? age(
String? value, {
int min = 1,
int max = 120,
String? errorMsg,
}) {
if (value == null || value.isEmpty) return 'Age is required';
final age = int.tryParse(value);
if (age == null) return 'Age must be a number';
if (age < min || age > max) {
return errorMsg ?? 'Age must be between $min and $max';
}
return null;
}