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

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 line 2 is always valid. 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
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"
10 #include "base/utf_string_conversions.h"
Ilya Sherman 2013/02/11 05:39:51 nit: Not needed?
groby-ooo-7-16 2013/02/11 22:47:53 Left over from patch 1 - removed. On 2013/02/11 05
8 #include "chrome/browser/autofill/credit_card.h" 11 #include "chrome/browser/autofill/credit_card.h"
9 12
10 namespace autofill { 13 namespace autofill {
11 14
12 bool IsValidCreditCardNumber(const string16& text) { 15 bool IsValidCreditCardNumber(const string16& text) {
13 string16 number = CreditCard::StripSeparators(text); 16 string16 number = CreditCard::StripSeparators(text);
14 17
15 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to 18 // Credit card numbers are at most 19 digits in length [1]. 12 digits seems to
16 // be a fairly safe lower-bound [2]. 19 // be a fairly safe lower-bound [2].
17 // [1] http://www.merriampark.com/anatomycc.htm 20 // [1] http://www.merriampark.com/anatomycc.htm
(...skipping 20 matching lines...) Expand all
38 sum += digit / 10 + digit % 10; 41 sum += digit / 10 + digit % 10;
39 } else { 42 } else {
40 sum += digit; 43 sum += digit;
41 } 44 }
42 odd = !odd; 45 odd = !odd;
43 } 46 }
44 47
45 return (sum % 10) == 0; 48 return (sum % 10) == 0;
46 } 49 }
47 50
51 bool IsValidCreditCardCSC(const string16& text) {
52 if (text.size() < 3U || text.size() > 4U)
53 return false;
54
55 for (string16::const_iterator iter = text.begin();
56 iter != text.end();
57 ++iter) {
58 if (!IsAsciiDigit(*iter))
59 return false;
60 }
61 return true;
62 }
63
48 } // namespace autofill 64 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698