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
-
- Object
- Validator<
String> - ValidatorWithMessage<
String> - CardValidator
Constructors
- CardValidator({required String message})
-
Creates a
CardValidatorinstance with a custom error message.
Properties
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