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

Side by Side Diff: chrome/browser/autofill/validation.cc

Issue 12213077: [Autofill] Credit Card validation for rAc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 7 years, 10 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
« no previous file with comments | « chrome/browser/autofill/validation.h ('k') | chrome/browser/autofill/validation_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/autofill/validation.h" 5 #include "chrome/browser/autofill/validation.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/time.h"
Ilya Sherman 2013/02/11 22:55:10 nit: Both of these #includes look like they are no
groby-ooo-7-16 2013/02/11 23:27:07 Oops, sorry. Done. On 2013/02/11 22:55:10, Ilya Sh
8 #include "chrome/browser/autofill/credit_card.h" 10 #include "chrome/browser/autofill/credit_card.h"
9 11
10 namespace autofill { 12 namespace autofill {
11 13
12 bool IsValidCreditCardNumber(const string16& text) { 14 bool IsValidCreditCardNumber(const string16& text) {
13 string16 number = CreditCard::StripSeparators(text); 15 string16 number = CreditCard::StripSeparators(text);
14 16
15 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to 17 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to
16 // be a fairly safe lower-bound [2]. 18 // be a fairly safe lower-bound [2].
17 // [1] http://www.merriampark.com/anatomycc.htm 19 // [1] http://www.merriampark.com/anatomycc.htm
(...skipping 20 matching lines...) Expand all
38 sum += digit / 10 + digit % 10; 40 sum += digit / 10 + digit % 10;
39 } else { 41 } else {
40 sum += digit; 42 sum += digit;
41 } 43 }
42 odd = !odd; 44 odd = !odd;
43 } 45 }
44 46
45 return (sum % 10) == 0; 47 return (sum % 10) == 0;
46 } 48 }
47 49
50 bool IsValidCreditCardSecurityCode(const string16& text) {
51 if (text.size() < 3U || text.size() > 4U)
52 return false;
53
54 for (string16::const_iterator iter = text.begin();
55 iter != text.end();
56 ++iter) {
57 if (!IsAsciiDigit(*iter))
58 return false;
59 }
60 return true;
61 }
62
48 } // namespace autofill 63 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/validation.h ('k') | chrome/browser/autofill/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698