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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 bool IsValidCreditCardNumber(const base::string16& text) { | 38 bool IsValidCreditCardNumber(const base::string16& text) { |
39 base::string16 number = CreditCard::StripSeparators(text); | 39 base::string16 number = CreditCard::StripSeparators(text); |
40 | 40 |
41 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to | 41 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to |
42 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly | 42 // be a fairly safe lower-bound [2]. Specific card issuers have more rigidly |
43 // defined sizes. | 43 // defined sizes. |
44 // [1] http://www.merriampark.com/anatomycc.htm | 44 // [1] http://www.merriampark.com/anatomycc.htm |
45 // [2] http://en.wikipedia.org/wiki/Bank_card_number | 45 // [2] http://en.wikipedia.org/wiki/Bank_card_number |
| 46 // CardEditor.isCardNumberLengthMaxium() needs to be kept in sync. |
46 const char* const type = CreditCard::GetCreditCardType(text); | 47 const char* const type = CreditCard::GetCreditCardType(text); |
47 if (type == kAmericanExpressCard && number.size() != 15) | 48 if (type == kAmericanExpressCard && number.size() != 15) |
48 return false; | 49 return false; |
49 if (type == kDinersCard && number.size() != 14) | 50 if (type == kDinersCard && number.size() != 14) |
50 return false; | 51 return false; |
51 if (type == kDiscoverCard && number.size() != 16) | 52 if (type == kDiscoverCard && number.size() != 16) |
52 return false; | 53 return false; |
53 if (type == kJCBCard && number.size() != 16) | 54 if (type == kJCBCard && number.size() != 16) |
54 return false; | 55 return false; |
55 if (type == kMasterCard && number.size() != 16) | 56 if (type == kMasterCard && number.size() != 16) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 number_string.begin() + 9), | 182 number_string.begin() + 9), |
182 &serial) | 183 &serial) |
183 || serial == 0) { | 184 || serial == 0) { |
184 return false; | 185 return false; |
185 } | 186 } |
186 | 187 |
187 return true; | 188 return true; |
188 } | 189 } |
189 | 190 |
190 } // namespace autofill | 191 } // namespace autofill |
OLD | NEW |