numericValidator static method

String? numericValidator(
  1. String? value, [
  2. String? errorMessage
])

numericValidator to validate a number

validator: (value) => SimpleValidations.numericValidator(value, [errorMessage]),

Implementation

static String? numericValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.numericRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter only numeric characters';
  }
  return null;
}