Chromium Code Reviews| Index: components/autofill/core/browser/validation.cc |
| diff --git a/components/autofill/core/browser/validation.cc b/components/autofill/core/browser/validation.cc |
| index 7bf3a938d4524288dbd6af27ab5a0bf149f4bc0a..ef7c4d233d5eef0b6dd6cb0ae82ae7f367f25458 100644 |
| --- a/components/autofill/core/browser/validation.cc |
| +++ b/components/autofill/core/browser/validation.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/time/time.h" |
| +#include "components/autofill/core/browser/autofill_data_util.h" |
| #include "components/autofill/core/browser/credit_card.h" |
| #include "components/autofill/core/browser/state_names.h" |
| #include "components/autofill/core/common/autofill_clock.h" |
| @@ -97,6 +98,33 @@ bool IsValidCreditCardSecurityCode(const base::string16& code, |
| base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789")); |
| } |
| +bool IsValidCreditCardNumberForBasicCardNetworks( |
| + const base::string16& text, |
| + const std::set<std::string>& supported_basic_card_networks, |
| + base::string16* error_message) { |
| + // The type check is cheaper than the credit card number check. |
| + const std::string basic_card_payment_type = |
| + autofill::data_util::GetPaymentRequestData( |
| + CreditCard::GetCreditCardType(text)) |
| + .basic_card_payment_type; |
| + if (!supported_basic_card_networks.count(basic_card_payment_type)) { |
| + if (error_message) { |
|
anthonyvd
2017/02/23 16:42:27
I would prefer just commenting in the .h that erro
Mathieu
2017/02/23 16:48:31
Good idea!
|
| + *error_message = l10n_util::GetStringUTF16( |
| + IDS_PAYMENTS_VALIDATION_UNSUPPORTED_CREDIT_CARD_TYPE); |
| + } |
| + return false; |
| + } |
| + |
| + if (IsValidCreditCardNumber(text)) |
| + return true; |
| + |
| + if (error_message) { |
| + *error_message = l10n_util::GetStringUTF16( |
| + IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| + } |
| + return false; |
| +} |
| + |
| bool IsValidEmailAddress(const base::string16& text) { |
| // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| const base::string16 kEmailPattern = base::ASCIIToUTF16( |
| @@ -268,13 +296,8 @@ bool IsValidForType(const base::string16& value, |
| } |
| case CREDIT_CARD_NUMBER: |
| - if (IsValidCreditCardNumber(value)) |
| - return true; |
| - |
| - if (error_message) { |
| - *error_message = l10n_util::GetStringUTF16( |
| - IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| - } |
| + NOTREACHED() << "IsValidCreditCardNumberForBasicCardNetworks should be " |
|
anthonyvd
2017/02/23 16:42:28
Are you sure this wasn't already used with CREDIT_
Mathieu
2017/02/23 16:48:31
Yes this function is new for PaymentRequest (I wro
anthonyvd
2017/02/23 17:00:18
Oh haha, my bad!
|
| + << "used to validate credit card numbers"; |
| break; |
| default: |