| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 sum += digit / 10 + digit % 10; | 80 sum += digit / 10 + digit % 10; |
| 81 } else { | 81 } else { |
| 82 sum += digit; | 82 sum += digit; |
| 83 } | 83 } |
| 84 odd = !odd; | 84 odd = !odd; |
| 85 } | 85 } |
| 86 | 86 |
| 87 return (sum % 10) == 0; | 87 return (sum % 10) == 0; |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool IsValidCreditCardSecurityCode(const base::string16& text) { | |
| 91 if (text.size() < 3U || text.size() > 4U) | |
| 92 return false; | |
| 93 | |
| 94 for (const base::char16& it : text) { | |
| 95 if (!base::IsAsciiDigit(it)) | |
| 96 return false; | |
| 97 } | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 bool IsValidCreditCardSecurityCode(const base::string16& code, | 90 bool IsValidCreditCardSecurityCode(const base::string16& code, |
| 102 const base::string16& number) { | 91 const base::StringPiece card_type) { |
| 103 const char* const type = CreditCard::GetCreditCardType(number); | 92 size_t required_length = card_type == kAmericanExpressCard ? 4 : 3; |
| 104 size_t required_length = 3; | 93 return code.length() == required_length && |
| 105 if (type == kAmericanExpressCard) | 94 base::ContainsOnlyChars(code, base::ASCIIToUTF16("0123456789")); |
| 106 required_length = 4; | |
| 107 | |
| 108 return code.length() == required_length; | |
| 109 } | 95 } |
| 110 | 96 |
| 111 bool IsValidEmailAddress(const base::string16& text) { | 97 bool IsValidEmailAddress(const base::string16& text) { |
| 112 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) | 98 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| 113 const base::string16 kEmailPattern = base::ASCIIToUTF16( | 99 const base::string16 kEmailPattern = base::ASCIIToUTF16( |
| 114 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" | 100 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" |
| 115 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); | 101 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); |
| 116 return MatchesPattern(text, kEmailPattern); | 102 return MatchesPattern(text, kEmailPattern); |
| 117 } | 103 } |
| 118 | 104 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 number_string.begin() + 9), | 168 number_string.begin() + 9), |
| 183 &serial) | 169 &serial) |
| 184 || serial == 0) { | 170 || serial == 0) { |
| 185 return false; | 171 return false; |
| 186 } | 172 } |
| 187 | 173 |
| 188 return true; | 174 return true; |
| 189 } | 175 } |
| 190 | 176 |
| 191 } // namespace autofill | 177 } // namespace autofill |
| OLD | NEW |