| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/validation.h" | 5 #include "components/autofill/core/browser/validation.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 bool IsValidCreditCardNumber(const base::string16& text) { | 45 bool IsValidCreditCardNumber(const base::string16& text) { |
| 46 base::string16 number = CreditCard::StripSeparators(text); | 46 base::string16 number = CreditCard::StripSeparators(text); |
| 47 | 47 |
| 48 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to | 48 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to |
| 49 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly | 49 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly |
| 50 // defined sizes. | 50 // defined sizes. |
| 51 // [1] http://www.merriampark.com/anatomycc.htm | 51 // [1] http://www.merriampark.com/anatomycc.htm |
| 52 // [2] http://en.wikipedia.org/wiki/Bank_card_number | 52 // [2] http://en.wikipedia.org/wiki/Bank_card_number |
| 53 // CardEditor.isCardNumberLengthMaxium() needs to be kept in sync. | 53 // CardEditor.isCardNumberLengthMaxium() needs to be kept in sync. |
| 54 const char* const type = CreditCard::GetCreditCardType(text); | 54 const char* const type = CreditCard::GetCardNetwork(text); |
| 55 if (type == kAmericanExpressCard && number.size() != 15) | 55 if (type == kAmericanExpressCard && number.size() != 15) |
| 56 return false; | 56 return false; |
| 57 if (type == kDinersCard && number.size() != 14) | 57 if (type == kDinersCard && number.size() != 14) |
| 58 return false; | 58 return false; |
| 59 if (type == kDiscoverCard && number.size() != 16) | 59 if (type == kDiscoverCard && number.size() != 16) |
| 60 return false; | 60 return false; |
| 61 if (type == kJCBCard && number.size() != 16) | 61 if (type == kJCBCard && number.size() != 16) |
| 62 return false; | 62 return false; |
| 63 if (type == kMasterCard && number.size() != 16) | 63 if (type == kMasterCard && number.size() != 16) |
| 64 return false; | 64 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789")); | 100 base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789")); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool IsValidCreditCardNumberForBasicCardNetworks( | 103 bool IsValidCreditCardNumberForBasicCardNetworks( |
| 104 const base::string16& text, | 104 const base::string16& text, |
| 105 const std::set<std::string>& supported_basic_card_networks, | 105 const std::set<std::string>& supported_basic_card_networks, |
| 106 base::string16* error_message) { | 106 base::string16* error_message) { |
| 107 DCHECK(error_message); | 107 DCHECK(error_message); |
| 108 | 108 |
| 109 // The type check is cheaper than the credit card number check. | 109 // The type check is cheaper than the credit card number check. |
| 110 const std::string basic_card_payment_type = | 110 const std::string basic_card_issuer_network = |
| 111 autofill::data_util::GetPaymentRequestData( | 111 autofill::data_util::GetPaymentRequestData( |
| 112 CreditCard::GetCreditCardType(text)) | 112 CreditCard::GetCardNetwork(text)) |
| 113 .basic_card_payment_type; | 113 .basic_card_issuer_network; |
| 114 if (!supported_basic_card_networks.count(basic_card_payment_type)) { | 114 if (!supported_basic_card_networks.count(basic_card_issuer_network)) { |
| 115 *error_message = l10n_util::GetStringUTF16( | 115 *error_message = l10n_util::GetStringUTF16( |
| 116 IDS_PAYMENTS_VALIDATION_UNSUPPORTED_CREDIT_CARD_TYPE); | 116 IDS_PAYMENTS_VALIDATION_UNSUPPORTED_CREDIT_CARD_TYPE); |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (IsValidCreditCardNumber(text)) | 120 if (IsValidCreditCardNumber(text)) |
| 121 return true; | 121 return true; |
| 122 | 122 |
| 123 *error_message = l10n_util::GetStringUTF16( | 123 *error_message = l10n_util::GetStringUTF16( |
| 124 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); | 124 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 return AMEX_CVC_LENGTH; | 365 return AMEX_CVC_LENGTH; |
| 366 | 366 |
| 367 return GENERAL_CVC_LENGTH; | 367 return GENERAL_CVC_LENGTH; |
| 368 } | 368 } |
| 369 | 369 |
| 370 bool IsUPIVirtualPaymentAddress(const base::string16& value) { | 370 bool IsUPIVirtualPaymentAddress(const base::string16& value) { |
| 371 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); | 371 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace autofill | 374 } // namespace autofill |
| OLD | NEW |