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 |