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

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

Issue 14148004: [Autofill] Move IsValidState() into validation.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't rely on a magic constant Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « components/autofill/browser/validation.h ('k') | no next file » | 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 "components/autofill/browser/validation.h" 5 #include "components/autofill/browser/validation.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "components/autofill/browser/autofill_regexes.h" 11 #include "components/autofill/browser/autofill_regexes.h"
12 #include "components/autofill/browser/credit_card.h" 12 #include "components/autofill/browser/credit_card.h"
13 #include "components/autofill/browser/state_names.h"
13 14
14 namespace autofill { 15 namespace autofill {
15 16
16 bool IsValidCreditCardExpirationDate(const base::string16& year, 17 bool IsValidCreditCardExpirationDate(const base::string16& year,
17 const base::string16& month, 18 const base::string16& month,
18 const base::Time& now) { 19 const base::Time& now) {
19 base::string16 year_cleaned, month_cleaned; 20 base::string16 year_cleaned, month_cleaned;
20 TrimWhitespace(year, TRIM_ALL, &year_cleaned); 21 TrimWhitespace(year, TRIM_ALL, &year_cleaned);
21 TrimWhitespace(month, TRIM_ALL, &month_cleaned); 22 TrimWhitespace(month, TRIM_ALL, &month_cleaned);
22 if (year_cleaned.length() != 4) 23 if (year_cleaned.length() != 4)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 104 }
104 105
105 bool IsValidEmailAddress(const base::string16& text) { 106 bool IsValidEmailAddress(const base::string16& text) {
106 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) 107 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state)
107 const base::string16 kEmailPattern = ASCIIToUTF16( 108 const base::string16 kEmailPattern = ASCIIToUTF16(
108 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" 109 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@"
109 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); 110 "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$");
110 return MatchesPattern(text, kEmailPattern); 111 return MatchesPattern(text, kEmailPattern);
111 } 112 }
112 113
113 bool IsValidZip(const base::string16& value) { 114 bool IsValidState(const base::string16& text) {
115 return !state_names::GetAbbreviationForName(text).empty() ||
116 !state_names::GetNameForAbbreviation(text).empty();
117 }
118
119 bool IsValidZip(const base::string16& text) {
114 const base::string16 kZipPattern = ASCIIToUTF16("^\\d{5}(-\\d{4})?$"); 120 const base::string16 kZipPattern = ASCIIToUTF16("^\\d{5}(-\\d{4})?$");
115 return MatchesPattern(value, kZipPattern); 121 return MatchesPattern(text, kZipPattern);
116 } 122 }
117 123
118 } // namespace autofill 124 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/validation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698