decimalValidator static method
decimalValidator to check whether a number is a valid decimal number
validator: (value) => SimpleValidations.decimalValidator(value, [errorMessage]),
Implementation
static String? decimalValidator(String? value, [String? errorMessage]) {
RegExp regex = CustomRegEx.decimalRegex;
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
} else if (!regex.hasMatch(value)) {
return errorMessage ?? 'Please enter a valid decimal number';
}
return null;
}