| 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/credit_card.h" | 16 #include "components/autofill/core/browser/credit_card.h" |
| 17 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 17 #include "components/autofill/core/browser/state_names.h" | 18 #include "components/autofill/core/browser/state_names.h" |
| 18 #include "components/autofill/core/common/autofill_clock.h" | 19 #include "components/autofill/core/common/autofill_clock.h" |
| 19 #include "components/autofill/core/common/autofill_regexes.h" | 20 #include "components/autofill/core/common/autofill_regexes.h" |
| 20 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 namespace autofill { | 24 namespace autofill { |
| 24 | 25 |
| 25 bool IsValidCreditCardExpirationDate(int year, | 26 bool IsValidCreditCardExpirationDate(int year, |
| 26 int month, | 27 int month, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" | 131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" |
| 131 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); | 132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); |
| 132 return MatchesPattern(text, kEmailPattern); | 133 return MatchesPattern(text, kEmailPattern); |
| 133 } | 134 } |
| 134 | 135 |
| 135 bool IsValidState(const base::string16& text) { | 136 bool IsValidState(const base::string16& text) { |
| 136 return !state_names::GetAbbreviationForName(text).empty() || | 137 return !state_names::GetAbbreviationForName(text).empty() || |
| 137 !state_names::GetNameForAbbreviation(text).empty(); | 138 !state_names::GetNameForAbbreviation(text).empty(); |
| 138 } | 139 } |
| 139 | 140 |
| 141 bool IsValidPhoneNumber(const base::string16& text, |
| 142 const std::string& country_code) { |
| 143 i18n::PhoneObject phone_number(text, country_code); |
| 144 return phone_number.IsValidNumber(); |
| 145 } |
| 146 |
| 140 bool IsValidZip(const base::string16& text) { | 147 bool IsValidZip(const base::string16& text) { |
| 141 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); | 148 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); |
| 142 return MatchesPattern(text, kZipPattern); | 149 return MatchesPattern(text, kZipPattern); |
| 143 } | 150 } |
| 144 | 151 |
| 145 bool IsSSN(const base::string16& text) { | 152 bool IsSSN(const base::string16& text) { |
| 146 base::string16 number_string; | 153 base::string16 number_string; |
| 147 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); | 154 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); |
| 148 | 155 |
| 149 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = | 156 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 default: | 309 default: |
| 303 // Other types such as CREDIT_CARD_TYPE and CREDIT_CARD_VERIFICATION_CODE | 310 // Other types such as CREDIT_CARD_TYPE and CREDIT_CARD_VERIFICATION_CODE |
| 304 // are not validated for now. | 311 // are not validated for now. |
| 305 NOTREACHED() << "Attempting to validate unsupported type " << type; | 312 NOTREACHED() << "Attempting to validate unsupported type " << type; |
| 306 break; | 313 break; |
| 307 } | 314 } |
| 308 return false; | 315 return false; |
| 309 } | 316 } |
| 310 | 317 |
| 311 } // namespace autofill | 318 } // namespace autofill |
| OLD | NEW |