numericOnly static method

String? numericOnly(
  1. String? value, {
  2. String? message,
})

Validates numeric characters only

Example:

Validators.numericOnly('123');

Implementation

static String? numericOnly(String? value, {String? message}) {
  if (value == null || value.isEmpty) return null;
  final regex = RegExp(r'^\d+$');
  if (!regex.hasMatch(value)) {
    return message ?? 'Only numeric characters are allowed';
  }
  return null;
}