Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: components/autofill/core/browser/validation.cc

Issue 16254010: [Autofill] Update credit card type detection logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/validation.cc
diff --git a/components/autofill/core/browser/validation.cc b/components/autofill/core/browser/validation.cc
index ca8c780ecdae02ab13efddf2d26dff3ea380a4cc..4dbe21c4c82db8544a95935f11248be2000905ed 100644
--- a/components/autofill/core/browser/validation.cc
+++ b/components/autofill/core/browser/validation.cc
@@ -57,13 +57,24 @@ bool IsValidCreditCardNumber(const base::string16& text) {
base::string16 number = CreditCard::StripSeparators(text);
// Credit card numbers are at most 19 digits in length [1]. 12 digits seems to
- // be a fairly safe lower-bound [2].
+ // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly
+ // defined sizes.
// [1] http://www.merriampark.com/anatomycc.htm
// [2] http://en.wikipedia.org/wiki/Bank_card_number
- const size_t kMinCreditCardDigits = 12;
- const size_t kMaxCreditCardDigits = 19;
- if (number.size() < kMinCreditCardDigits ||
- number.size() > kMaxCreditCardDigits)
+ const std::string type = CreditCard::GetCreditCardType(text);
+ if (type == kAmericanExpressCard && number.size() != 15)
+ return false;
+ if (type == kDinersCard && number.size() != 14)
+ return false;
+ if (type == kDiscoverCard && number.size() != 16)
+ return false;
+ if (type == kJCBCard && number.size() != 16)
+ return false;
+ if (type == kMasterCard && number.size() != 16)
+ return false;
+ if (type == kVisaCard && number.size() != 13 && number.size() != 16)
+ return false;
+ if (type == kGenericCard && (number.size() < 12 || number.size() > 19))
return false;
// Use the Luhn formula [3] to validate the number.
« no previous file with comments | « components/autofill/core/browser/personal_data_manager_unittest.cc ('k') | components/component_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698