| 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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 card.SetRawInfo(CREDIT_CARD_NUMBER, number); | 132 card.SetRawInfo(CREDIT_CARD_NUMBER, number); |
| 133 size_t required_length = 3; | 133 size_t required_length = 3; |
| 134 if (card.type() == kAmericanExpressCard) | 134 if (card.type() == kAmericanExpressCard) |
| 135 required_length = 4; | 135 required_length = 4; |
| 136 | 136 |
| 137 return code.length() == required_length; | 137 return code.length() == required_length; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool IsValidEmailAddress(const base::string16& text) { | 140 bool IsValidEmailAddress(const base::string16& text) { |
| 141 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) | 141 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| 142 const base::string16 kEmailPattern = ASCIIToUTF16( | 142 const base::string16 kEmailPattern = base::ASCIIToUTF16( |
| 143 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" | 143 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" |
| 144 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); | 144 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); |
| 145 return MatchesPattern(text, kEmailPattern); | 145 return MatchesPattern(text, kEmailPattern); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool IsValidState(const base::string16& text) { | 148 bool IsValidState(const base::string16& text) { |
| 149 return !state_names::GetAbbreviationForName(text).empty() || | 149 return !state_names::GetAbbreviationForName(text).empty() || |
| 150 !state_names::GetNameForAbbreviation(text).empty(); | 150 !state_names::GetNameForAbbreviation(text).empty(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool IsValidZip(const base::string16& text) { | 153 bool IsValidZip(const base::string16& text) { |
| 154 const base::string16 kZipPattern = ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); | 154 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); |
| 155 return MatchesPattern(text, kZipPattern); | 155 return MatchesPattern(text, kZipPattern); |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool IsSSN(const base::string16& text) { | 158 bool IsSSN(const base::string16& text) { |
| 159 base::string16 number_string; | 159 base::string16 number_string; |
| 160 base::RemoveChars(text, kSSNSeparators, &number_string); | 160 base::RemoveChars(text, kSSNSeparators, &number_string); |
| 161 | 161 |
| 162 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = | 162 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = |
| 163 // serial number). The validation we do here is simply checking if the area, | 163 // serial number). The validation we do here is simply checking if the area, |
| 164 // group, and serial numbers are valid. | 164 // group, and serial numbers are valid. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 number_string.begin() + 9), | 211 number_string.begin() + 9), |
| 212 &serial) | 212 &serial) |
| 213 || serial == 0) { | 213 || serial == 0) { |
| 214 return false; | 214 return false; |
| 215 } | 215 } |
| 216 | 216 |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace autofill | 220 } // namespace autofill |
| OLD | NEW |