| 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..3a613e29d32421628a3b3bfe99879925af9b1fe5 100644
|
| --- a/components/autofill/core/browser/validation.cc
|
| +++ b/components/autofill/core/browser/validation.cc
|
| @@ -6,11 +6,13 @@
|
|
|
| #include <stddef.h>
|
|
|
| +#include "base/logging.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_piece.h"
|
| #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 +99,31 @@ 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) {
|
| + DCHECK(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)) {
|
| + *error_message = l10n_util::GetStringUTF16(
|
| + IDS_PAYMENTS_VALIDATION_UNSUPPORTED_CREDIT_CARD_TYPE);
|
| + return false;
|
| + }
|
| +
|
| + if (IsValidCreditCardNumber(text))
|
| + return true;
|
| +
|
| + *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 +295,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 "
|
| + << "used to validate credit card numbers";
|
| break;
|
|
|
| default:
|
|
|