CardValidator class

Client-side card validation utilities.

This class provides static methods for validating card information before sending to the backend. No network calls are made.

Example

// Validate a single field
if (!CardValidator.isValidCardNumber(cardNumber)) {
  showError('Invalid card number');
}

// Validate all fields at once
final result = CardValidator.validate(
  cardNumber: '5528790000000008',
  expireMonth: '12',
  expireYear: '2030',
  cvv: '123',
  holderName: 'Ahmet Yilmaz',
);

if (!result.isValid) {
  print(result.errors); // {'cardNumber': 'Invalid card number'}
}

// Detect card brand
final brand = CardValidator.detectCardBrand('4111111111111111');
print(brand.displayName); // 'Visa'

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

detectCardBrand(String cardNumber) CardBrand
Detects the card brand from the card number.
extractBin(String cardNumber, {int length = 6}) String
Extracts the BIN (Bank Identification Number) from a card number.
formatCardNumber(String cardNumber) String
Formats a card number with spaces for display.
isValidCardNumber(String cardNumber) bool
Validates a card number using the Luhn algorithm.
isValidCVV(String cvv, {CardBrand? cardBrand}) bool
Validates a CVV/CVC code.
isValidExpiry(String month, String year) bool
Validates the card expiry date.
isValidHolderName(String name) bool
Validates the card holder name.
maskCardNumber(String cardNumber) String
Masks a card number for display, showing only BIN and last 4 digits.
validate({required String cardNumber, required String expireMonth, required String expireYear, required String cvv, required String holderName}) CardValidationResult
Validates all card information at once.