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" |
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return MatchesPattern(text, kEmailPattern); | 170 return MatchesPattern(text, kEmailPattern); |
171 } | 171 } |
172 | 172 |
173 bool IsValidState(const base::string16& text) { | 173 bool IsValidState(const base::string16& text) { |
174 return !state_names::GetAbbreviationForName(text).empty() || | 174 return !state_names::GetAbbreviationForName(text).empty() || |
175 !state_names::GetNameForAbbreviation(text).empty(); | 175 !state_names::GetNameForAbbreviation(text).empty(); |
176 } | 176 } |
177 | 177 |
178 bool IsValidPhoneNumber(const base::string16& text, | 178 bool IsValidPhoneNumber(const base::string16& text, |
179 const std::string& country_code) { | 179 const std::string& country_code) { |
180 i18n::PhoneObject phone_number(text, country_code); | 180 ::i18n::phonenumbers::PhoneNumber parsed_number; |
181 return phone_number.IsValidNumber(); | 181 ::i18n::phonenumbers::PhoneNumberUtil* phone_number_util = |
| 182 ::i18n::phonenumbers::PhoneNumberUtil::GetInstance(); |
| 183 if (phone_number_util->Parse(base::UTF16ToUTF8(text), country_code, |
| 184 &parsed_number) != |
| 185 ::i18n::phonenumbers::PhoneNumberUtil::NO_PARSING_ERROR) { |
| 186 return false; |
| 187 } |
| 188 |
| 189 return phone_number_util->IsValidNumber(parsed_number); |
182 } | 190 } |
183 | 191 |
184 bool IsValidZip(const base::string16& text) { | 192 bool IsValidZip(const base::string16& text) { |
185 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); | 193 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); |
186 return MatchesPattern(text, kZipPattern); | 194 return MatchesPattern(text, kZipPattern); |
187 } | 195 } |
188 | 196 |
189 bool IsSSN(const base::string16& text) { | 197 bool IsSSN(const base::string16& text) { |
190 base::string16 number_string; | 198 base::string16 number_string; |
191 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); | 199 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return AMEX_CVC_LENGTH; | 365 return AMEX_CVC_LENGTH; |
358 | 366 |
359 return GENERAL_CVC_LENGTH; | 367 return GENERAL_CVC_LENGTH; |
360 } | 368 } |
361 | 369 |
362 bool IsUPIVirtualPaymentAddress(const base::string16& value) { | 370 bool IsUPIVirtualPaymentAddress(const base::string16& value) { |
363 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); | 371 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); |
364 } | 372 } |
365 | 373 |
366 } // namespace autofill | 374 } // namespace autofill |
OLD | NEW |