numericValidator static method
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;
}