validInput function

dynamic validInput(
  1. String val, {
  2. bool isEmail = false,
  3. bool isRequire = false,
  4. bool isPhone = false,
  5. bool isNumber = false,
  6. bool isDateTime = false,
  7. int min = 0,
  8. int max = 0,
})

Implementation

validInput(
  String val, {
  bool isEmail = false,
  bool isRequire = false,
  bool isPhone = false,
  bool isNumber = false,
  bool isDateTime = false,
  int min = 0,
  int max = 0,
}) {
  if (val.isEmpty) {
    return "2".tr;
  }

  if (isEmail && !GetUtils.isEmail(val)) {
    return "3".tr;
  }
  if (isPhone && !GetUtils.isPhoneNumber(val)) {
    return "4".tr;
  }
  if (isNumber && !GetUtils.isNumericOnly(val)) {
    return "5".tr;
  }
  if (isDateTime && !GetUtils.isDateTime(val)) {
    return "8".tr;
  }

  if (min != 0 && val.length < min) {
    return "6".tr;
  }

  if (max != 0 && val.length > max) {
    return "7".tr;
  }
}