mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Fix the card validator.
This commit is contained in:
parent
b8c510ca6d
commit
c327fa0d45
1 changed files with 21 additions and 6 deletions
|
@ -193,13 +193,28 @@ CardValidationResult ValidateCard(const QString &number) {
|
|||
}
|
||||
const auto range = MostSpecificBinRangeForNumber(sanitized);
|
||||
const auto brand = range.brand;
|
||||
//if (sanitized.size() > range.length) {
|
||||
// return { .state = ValidationState::Invalid, .brand = brand };
|
||||
//} else if (sanitized.size() < range.length) {
|
||||
// return { .state = ValidationState::Incomplete, .brand = brand };
|
||||
//} else
|
||||
if (!IsValidLuhn(sanitized)) {
|
||||
|
||||
static const auto &all = AllRanges();
|
||||
static const auto compare = [](const BinRange &a, const BinRange &b) {
|
||||
return a.length < b.length;
|
||||
};
|
||||
static const auto kMinLength = std::min_element(
|
||||
begin(all),
|
||||
end(all),
|
||||
compare)->length;
|
||||
static const auto kMaxLength = std::max_element(
|
||||
begin(all),
|
||||
end(all),
|
||||
compare)->length;
|
||||
|
||||
if (sanitized.size() > kMaxLength) {
|
||||
return { .state = ValidationState::Invalid, .brand = brand };
|
||||
} else if (sanitized.size() < kMinLength) {
|
||||
return { .state = ValidationState::Incomplete, .brand = brand };
|
||||
} else if (!IsValidLuhn(sanitized)) {
|
||||
return { .state = ValidationState::Invalid, .brand = brand };
|
||||
} else if (sanitized.size() < kMaxLength) {
|
||||
return { .state = ValidationState::Valid, .brand = brand };
|
||||
}
|
||||
return {
|
||||
.state = ValidationState::Valid,
|
||||
|
|
Loading…
Add table
Reference in a new issue