Index: chrome/browser/autofill/credit_card.cc |
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc |
index 26ed7850c2145d73f524b728d387f4aa7d10e0cb..d588316a32a2938181947a9fc138601f07e5ed48 100644 |
--- a/chrome/browser/autofill/credit_card.cc |
+++ b/chrome/browser/autofill/credit_card.cc |
@@ -8,6 +8,7 @@ |
#include "app/l10n_util.h" |
#include "base/basictypes.h" |
+#include "base/string_split.h" |
#include "base/string_util.h" |
#include "base/string_number_conversions.h" |
#include "base/string16.h" |
@@ -16,6 +17,8 @@ |
#include "chrome/browser/autofill/field_types.h" |
#include "chrome/common/guid.h" |
#include "grit/generated_resources.h" |
+#include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h" |
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
namespace { |
@@ -455,6 +458,26 @@ bool CreditCard::IsEmpty() const { |
return types.empty(); |
} |
+void CreditCard::SetMonthInputInfo(const string16& value) { |
+ // Check if |text| is "yyyy-mm" format first, and check normal month format. |
+ WebKit::WebRegularExpression re(WebKit::WebString("^[0-9]{4}\\-[0-9]{1,2}$"), |
+ WebKit::WebTextCaseInsensitive); |
+ bool match = re.match(WebKit::WebString(StringToLowerASCII(value))) != -1; |
+ if (match) { |
+ std::vector<string16> year_month; |
+ base::SplitString(value, L'-', &year_month); |
+ DCHECK(year_month.size() == 2); |
+ int num = 0; |
+ bool converted = false; |
+ converted = base::StringToInt(year_month[0], &num); |
+ DCHECK(converted); |
+ set_expiration_year(num); |
+ converted = base::StringToInt(year_month[1], &num); |
+ DCHECK(converted); |
+ set_expiration_month(num); |
+ } |
+} |
+ |
honten.org
2011/01/06 07:04:54
Use regular expression to check yyyy-mm.
dhollowa
2011/01/07 03:47:15
Nice.
On 2011/01/06 07:04:54, honten wrote:
|
string16 CreditCard::ExpirationMonthAsString() const { |
if (expiration_month_ == 0) |
return string16(); |