numeric static method

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

Validate numeric value

Implementation

static String? numeric(String? value, {String? fieldName}) {
  if (value == null || value.isEmpty) {
    return '${fieldName ?? 'This field'} is required';
  }

  final numericValue = double.tryParse(value);
  if (numericValue == null) {
    return '${fieldName ?? 'This field'} must be a valid number';
  }

  return null;
}