validateMoney method

String? validateMoney(
  1. String valueWithCurency,
  2. int minimalValue, {
  3. String? errorMessage,
  4. String? errorMessage2,
  5. String? errorMessage3,
})

Implementation

String? validateMoney(String valueWithCurency, int minimalValue,
    {String? errorMessage, String? errorMessage2, String? errorMessage3}) {
  var value = TextHelper().removeCurrency(valueWithCurency);
  if (value.isEmpty) return errorMessage ?? errorEmpty;
  try {
    if (int.parse(value) < minimalValue)
      return errorMessage2 ??
          'Harus lebih dari ${TextHelper().getCurrency(minimalValue)}';
  } catch (e) {
    return errorMessage3 ?? "Format tidak sesuai";
  }
  return null;
}