currencyAmount static method
Validate currency amount
Implementation
static String? currencyAmount(String? value, {String? fieldName}) {
if (value == null || value.isEmpty) {
return '${fieldName ?? 'Amount'} is required';
}
final amount = double.tryParse(value);
if (amount == null) {
return '${fieldName ?? 'Amount'} must be a valid number';
}
if (amount < 0) {
return '${fieldName ?? 'Amount'} cannot be negative';
}
// Check for reasonable decimal places (max 2 for currency)
final decimalPlaces =
value.split('.').length > 1 ? value.split('.')[1].length : 0;
if (decimalPlaces > 2) {
return '${fieldName ?? 'Amount'} cannot have more than 2 decimal places';
}
return null;
}