creditCardValidator static method

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

creditCardValidator to validate credit card number

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

Implementation

static String? creditCardValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.creditCardRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid credit card number';
  }
  return null;
}