nonNegativeNumber static method

String? nonNegativeNumber(
  1. String? value, {
  2. String? fieldName,
})

Validate non-negative number

Implementation

static String? nonNegativeNumber(String? value, {String? fieldName}) {
  final numericError = numeric(value, fieldName: fieldName);
  if (numericError != null) return numericError;

  final numericValue = double.parse(value!);
  if (numericValue < 0) {
    return '${fieldName ?? 'This field'} cannot be negative';
  }

  return null;
}