cardNumberValidator function
Implementation
String? cardNumberValidator(String? value) {
if (value == null || value.isEmpty || value == '') {
return 'Card Number is Required';
}
if (CardUtils.getCardTypeFrmNumber(value) == CardType.invalid ||
CardUtils.getCardTypeFrmNumber(value) == CardType.others) {
return 'Only VISA and MASTERCARD cards are allowed';
}
String cleanedValue = value.replaceAll(' ', '');
if (cleanedValue.length < 16) {
return '16 Digits Card Number Required';
}
if (!_validateCardNumberWithLuhnAlgorithm(cleanedValue)) {
return 'Invalid Card Number';
}
return null;
}