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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp

Issue 1753543002: PaymentRequest Mojo bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interface
Patch Set: haraken@'s + esprehn@'s comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp b/third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4072b65c2877cfdacc5a5a935c0d3f5a2c411ae5
--- /dev/null
+++ b/third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/payments/PaymentsValidators.h"
+
+#include "bindings/core/v8/ScriptRegexp.h"
+#include "wtf/text/StringImpl.h"
+
+namespace blink {
+
+bool PaymentsValidators::isValidCurrencyCodeFormat(const String& code, String* optionalErrorMessage)
+{
+ if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0)
+ return true;
+
+ if (optionalErrorMessage)
+ *optionalErrorMessage = "'" + code + "' is not a valid ISO 4217 currency code, should be 3 upper case letters [A-Z]";
+
+ return false;
+}
+
+bool PaymentsValidators::isValidAmountFormat(const String& amount, String* optionalErrorMessage)
+{
+ if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount) == 0)
+ return true;
+
+ if (optionalErrorMessage)
+ *optionalErrorMessage = "'" + amount + "' is not a valid ISO 20022 CurrencyAnd30Amount";
+
+ return false;
+}
+
+bool PaymentsValidators::isValidRegionCodeFormat(const String& code, String* optionalErrorMessage)
+{
+ if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0)
+ return true;
+
+ if (optionalErrorMessage)
+ *optionalErrorMessage = "'" + code + "' is not a valid ISO 3166 country code, should be 2 upper case letters [A-Z]";
+
+ return false;
+}
+
+bool PaymentsValidators::isValidLanguageCodeFormat(const String& code, String* optionalErrorMessage)
+{
+ if (ScriptRegexp("^([a-z]{2,3})?$", TextCaseSensitive).match(code) == 0)
+ return true;
+
+ if (optionalErrorMessage)
+ *optionalErrorMessage = "'" + code + "' is not a valid ISO 639 language code, should be 2-3 lower case letters [a-z]";
+
+ return false;
+}
+
+bool PaymentsValidators::isValidScriptCodeFormat(const String& code, String* optionalErrorMessage)
+{
+ if (ScriptRegexp("^([A-Z][a-z]{3})?$", TextCaseSensitive).match(code) == 0)
+ return true;
+
+ if (optionalErrorMessage)
+ *optionalErrorMessage = "'" + code + "' is not a valid ISO 1524 script code, should be an upper case letter [A-Z] followed by 3 lower case letters [a-z]";
+
+ return false;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698