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

Side by Side Diff: components/autofill/core/browser/validation.cc

Issue 2816083002: [WebPayments] Desktop implementation of Contact Editor (Closed)
Patch Set: compile error + rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/autofill/core/browser/autofill_data_util.h" 15 #include "components/autofill/core/browser/autofill_data_util.h"
16 #include "components/autofill/core/browser/autofill_regex_constants.h" 16 #include "components/autofill/core/browser/autofill_regex_constants.h"
17 #include "components/autofill/core/browser/credit_card.h" 17 #include "components/autofill/core/browser/credit_card.h"
18 #include "components/autofill/core/browser/phone_number_i18n.h"
19 #include "components/autofill/core/browser/state_names.h" 18 #include "components/autofill/core/browser/state_names.h"
20 #include "components/autofill/core/common/autofill_clock.h" 19 #include "components/autofill/core/common/autofill_clock.h"
21 #include "components/autofill/core/common/autofill_regexes.h" 20 #include "components/autofill/core/common/autofill_regexes.h"
22 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
22 #include "third_party/libphonenumber/phonenumber_api.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 24
25 namespace autofill { 25 namespace autofill {
26 26
27 bool IsValidCreditCardExpirationDate(int year, 27 bool IsValidCreditCardExpirationDate(int year,
28 int month, 28 int month,
29 const base::Time& now) { 29 const base::Time& now) {
30 if (month < 1 || month > 12) 30 if (month < 1 || month > 12)
31 return false; 31 return false;
32 32
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return MatchesPattern(text, kEmailPattern); 133 return MatchesPattern(text, kEmailPattern);
134 } 134 }
135 135
136 bool IsValidState(const base::string16& text) { 136 bool IsValidState(const base::string16& text) {
137 return !state_names::GetAbbreviationForName(text).empty() || 137 return !state_names::GetAbbreviationForName(text).empty() ||
138 !state_names::GetNameForAbbreviation(text).empty(); 138 !state_names::GetNameForAbbreviation(text).empty();
139 } 139 }
140 140
141 bool IsValidPhoneNumber(const base::string16& text, 141 bool IsValidPhoneNumber(const base::string16& text,
142 const std::string& country_code) { 142 const std::string& country_code) {
143 i18n::PhoneObject phone_number(text, country_code); 143 ::i18n::phonenumbers::PhoneNumber parsed_number;
144 return phone_number.IsValidNumber(); 144 ::i18n::phonenumbers::PhoneNumberUtil* phone_number_util =
145 ::i18n::phonenumbers::PhoneNumberUtil::GetInstance();
146 if (phone_number_util->Parse(base::UTF16ToUTF8(text), country_code,
147 &parsed_number) !=
148 ::i18n::phonenumbers::PhoneNumberUtil::NO_PARSING_ERROR) {
149 return false;
150 }
151
152 return phone_number_util->IsValidNumber(parsed_number);
145 } 153 }
146 154
147 bool IsValidZip(const base::string16& text) { 155 bool IsValidZip(const base::string16& text) {
148 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); 156 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$");
149 return MatchesPattern(text, kZipPattern); 157 return MatchesPattern(text, kZipPattern);
150 } 158 }
151 159
152 bool IsSSN(const base::string16& text) { 160 bool IsSSN(const base::string16& text) {
153 base::string16 number_string; 161 base::string16 number_string;
154 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); 162 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return AMEX_CVC_LENGTH; 328 return AMEX_CVC_LENGTH;
321 329
322 return GENERAL_CVC_LENGTH; 330 return GENERAL_CVC_LENGTH;
323 } 331 }
324 332
325 bool IsUPIVirtualPaymentAddress(const base::string16& value) { 333 bool IsUPIVirtualPaymentAddress(const base::string16& value) {
326 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); 334 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe));
327 } 335 }
328 336
329 } // namespace autofill 337 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698