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

Side by Side Diff: components/autofill/core/browser/validation.cc

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reviews Created 5 years 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 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const char* const type = CreditCard::GetCreditCardType(number); 120 const char* const type = CreditCard::GetCreditCardType(number);
121 size_t required_length = 3; 121 size_t required_length = 3;
122 if (type == kAmericanExpressCard) 122 if (type == kAmericanExpressCard)
123 required_length = 4; 123 required_length = 4;
124 124
125 return code.length() == required_length; 125 return code.length() == required_length;
126 } 126 }
127 127
128 bool IsValidEmailAddress(const base::string16& text) { 128 bool IsValidEmailAddress(const base::string16& text) {
129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) 129 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state)
130 const base::string16 kEmailPattern = base::ASCIIToUTF16( 130 const char kEmailPattern[] =
131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" 131 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@"
132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); 132 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$";
133 return MatchesPattern(text, kEmailPattern); 133 return MatchesPattern(text, kEmailPattern);
134 } 134 }
135 135
136 bool IsValidState(const base::string16& text) { 136 bool IsValidState(const base::string16& text) {
137 return !state_names::GetAbbreviationForName(text).empty() || 137 return !state_names::GetAbbreviationForName(text).empty() ||
138 !state_names::GetNameForAbbreviation(text).empty(); 138 !state_names::GetNameForAbbreviation(text).empty();
139 } 139 }
140 140
141 bool IsValidZip(const base::string16& text) { 141 bool IsValidZip(const base::string16& text) {
142 const base::string16 kZipPattern = base::ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); 142 const char kZipPattern[] = "^\\d{5}(-\\d{4})?$";
143 return MatchesPattern(text, kZipPattern); 143 return MatchesPattern(text, kZipPattern);
144 } 144 }
145 145
146 bool IsSSN(const base::string16& text) { 146 bool IsSSN(const base::string16& text) {
147 base::string16 number_string; 147 base::string16 number_string;
148 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string); 148 base::RemoveChars(text, base::ASCIIToUTF16("- "), &number_string);
149 149
150 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = 150 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S =
151 // serial number). The validation we do here is simply checking if the area, 151 // serial number). The validation we do here is simply checking if the area,
152 // group, and serial numbers are valid. 152 // group, and serial numbers are valid.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 number_string.begin() + 9), 199 number_string.begin() + 9),
200 &serial) 200 &serial)
201 || serial == 0) { 201 || serial == 0) {
202 return false; 202 return false;
203 } 203 }
204 204
205 return true; 205 return true;
206 } 206 }
207 207
208 } // namespace autofill 208 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698