CardValidator class

A validator that checks whether a given string is a valid credit or debit card number.

This validator ensures:

  • The number consists of only digits (excluding spaces/hyphens).
  • The length is between 13 and 19 digits.
  • The number passes the Luhn Algorithm, which is used to validate card numbers.

Example

final cardValidator = CardValidator(message: 'Invalid card number');

print(cardValidator.validate('4111111111111111')); // null (valid)
print(cardValidator.validate('1234567812345678')); // 'Invalid card number' (invalid)

Parameters

  • message: Custom error message when validation fails.
Inheritance

Constructors

CardValidator({required String message})
Creates a CardValidator instance with a custom error message.

Properties

hashCode int
The hash code for this object.
no setterinherited
message String
The error message to be returned when validation fails.
finalinherited
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
validate(covariant String value) String?
Validates the provided value.
override

Operators

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