mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 range = MostSpecificBinRangeForNumber(sanitized);
|
||||||
const auto brand = range.brand;
|
const auto brand = range.brand;
|
||||||
//if (sanitized.size() > range.length) {
|
|
||||||
// return { .state = ValidationState::Invalid, .brand = brand };
|
static const auto &all = AllRanges();
|
||||||
//} else if (sanitized.size() < range.length) {
|
static const auto compare = [](const BinRange &a, const BinRange &b) {
|
||||||
// return { .state = ValidationState::Incomplete, .brand = brand };
|
return a.length < b.length;
|
||||||
//} else
|
};
|
||||||
if (!IsValidLuhn(sanitized)) {
|
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 };
|
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 {
|
return {
|
||||||
.state = ValidationState::Valid,
|
.state = ValidationState::Valid,
|
||||||
|
|
Loading…
Add table
Reference in a new issue