ageValidator static method

String? ageValidator(
  1. int? value, [
  2. String? errorMessage
])

ageValidator to validate age

validator: (value) => SimpleValidations.ageValidator(value, [errorMessage]),

Implementation

static String? ageValidator(int? value, [String? errorMessage]) {
  if (value == null) {
    return errorMessage ?? 'Required';
  } else if (value <= 0 || value > 150) {
    return errorMessage ?? 'Please enter a valid age';
  }
  return null;
}