creditCard static method

FormFieldValidator<String> creditCard({
  1. String? errorText,
  2. bool checkNullOrEmpty = true,
})

FormFieldValidator that requires the field's value to be a valid credit card number.

Parameters:

  • errorText The error message when the credit card number is invalid.
  • checkNullOrEmpty Whether to check for null or empty values.

This regex matches credit card numbers from major brands.

  • It supports Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards.
  • It validates the number of digits and prefixes for each card type.

Examples: 4111111111111111, 5500000000000004, 340000000000009

Implementation

static FormFieldValidator<String> creditCard({
  String? errorText,
  bool checkNullOrEmpty = true,
}) => CreditCardValidator(
  errorText: errorText,
  checkNullOrEmpty: checkNullOrEmpty,
).validate;