Chromium Code Reviews| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool CreditCardHasNumberAndName(const CreditCard& card, | |
| 129 const std::string& app_locale) { | |
| 130 return !card.number().empty() && | |
| 131 !card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), | |
| 132 app_locale) | |
| 133 .empty(); | |
| 134 } | |
| 135 | |
| 136 bool IsCompleteForPaymentRequest(const CreditCard& card, | |
|
anthonyvd
2017/04/13 19:50:55
I think this could return a bitfield enum instead
Mathieu
2017/04/13 20:00:15
This is intentional because we want this file to b
anthonyvd
2017/04/13 20:48:27
Totally understand the need to have a common funct
Mathieu
2017/04/18 17:26:01
Cool, it's better now, PTAL
| |
| 137 const std::string& app_locale, | |
| 138 base::string16* missing_info) { | |
| 139 base::string16 message; | |
| 140 if (card.IsExpired(autofill::AutofillClock::Now())) { | |
| 141 message = l10n_util::GetStringUTF16( | |
| 142 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED); | |
| 143 } | |
| 144 if (card.number().empty()) { | |
| 145 if (!message.empty()) { | |
| 146 if (missing_info) { | |
| 147 *missing_info = | |
| 148 l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); | |
| 149 } | |
| 150 return false; | |
| 151 } | |
| 152 message = l10n_util::GetStringUTF16( | |
| 153 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); | |
| 154 } | |
| 155 if (card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), | |
| 156 app_locale) | |
| 157 .empty()) { | |
| 158 if (!message.empty()) { | |
| 159 if (missing_info) { | |
| 160 *missing_info = | |
| 161 l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); | |
| 162 } | |
| 163 return false; | |
| 164 } | |
| 165 message = l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED); | |
| 166 } | |
| 167 | |
| 168 if (!message.empty()) { | |
| 169 if (missing_info) | |
| 170 *missing_info = std::move(message); | |
| 171 return false; | |
| 172 } | |
| 173 return true; | |
| 174 } | |
| 175 | |
| 128 bool IsValidEmailAddress(const base::string16& text) { | 176 bool IsValidEmailAddress(const base::string16& text) { |
| 129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) | 177 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| 130 const base::string16 kEmailPattern = base::ASCIIToUTF16( | 178 const base::string16 kEmailPattern = base::ASCIIToUTF16( |
| 131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" | 179 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" |
| 132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); | 180 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); |
| 133 return MatchesPattern(text, kEmailPattern); | 181 return MatchesPattern(text, kEmailPattern); |
| 134 } | 182 } |
| 135 | 183 |
| 136 bool IsValidState(const base::string16& text) { | 184 bool IsValidState(const base::string16& text) { |
| 137 return !state_names::GetAbbreviationForName(text).empty() || | 185 return !state_names::GetAbbreviationForName(text).empty() || |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 return AMEX_CVC_LENGTH; | 368 return AMEX_CVC_LENGTH; |
| 321 | 369 |
| 322 return GENERAL_CVC_LENGTH; | 370 return GENERAL_CVC_LENGTH; |
| 323 } | 371 } |
| 324 | 372 |
| 325 bool IsUPIVirtualPaymentAddress(const base::string16& value) { | 373 bool IsUPIVirtualPaymentAddress(const base::string16& value) { |
| 326 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); | 374 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); |
| 327 } | 375 } |
| 328 | 376 |
| 329 } // namespace autofill | 377 } // namespace autofill |
| OLD | NEW |