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..c8ba69c811dd2a0f8f97663c237232a3017d6466 |
--- /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 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 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 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 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 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 |