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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
15 #include "components/autofill/core/browser/state_names.h" | 15 #include "components/autofill/core/browser/state_names.h" |
16 #include "components/autofill/core/common/autofill_regexes.h" | 16 #include "components/autofill/core/common/autofill_regexes.h" |
17 | 17 |
18 namespace autofill { | 18 namespace autofill { |
19 | 19 |
20 bool IsValidCreditCardExpirationDate(const base::string16& year, | |
21 const base::string16& month, | |
22 const base::Time& now) { | |
23 base::string16 year_cleaned, month_cleaned; | |
24 base::TrimWhitespace(year, base::TRIM_ALL, &year_cleaned); | |
25 base::TrimWhitespace(month, base::TRIM_ALL, &month_cleaned); | |
26 if (year_cleaned.length() != 4) | |
27 return false; | |
28 | |
29 int cc_year; | |
30 if (!base::StringToInt(year_cleaned, &cc_year)) | |
31 return false; | |
32 | |
33 int cc_month; | |
34 if (!base::StringToInt(month_cleaned, &cc_month)) | |
35 return false; | |
36 | |
37 return IsValidCreditCardExpirationDate(cc_year, cc_month, now); | |
38 } | |
39 | |
40 bool IsValidCreditCardExpirationDate(int year, | 20 bool IsValidCreditCardExpirationDate(int year, |
41 int month, | 21 int month, |
42 const base::Time& now) { | 22 const base::Time& now) { |
43 if (month < 1 || month > 12) | 23 if (month < 1 || month > 12) |
44 return false; | 24 return false; |
45 | 25 |
46 base::Time::Exploded now_exploded; | 26 base::Time::Exploded now_exploded; |
47 now.LocalExplode(&now_exploded); | 27 now.LocalExplode(&now_exploded); |
48 | 28 |
49 if (year < now_exploded.year) | 29 if (year < now_exploded.year) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 number_string.begin() + 9), | 184 number_string.begin() + 9), |
205 &serial) | 185 &serial) |
206 || serial == 0) { | 186 || serial == 0) { |
207 return false; | 187 return false; |
208 } | 188 } |
209 | 189 |
210 return true; | 190 return true; |
211 } | 191 } |
212 | 192 |
213 } // namespace autofill | 193 } // namespace autofill |
OLD | NEW |