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

Side by Side 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, 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/payments/PaymentsValidators.h"
6
7 #include "bindings/core/v8/ScriptRegexp.h"
8 #include "wtf/text/StringImpl.h"
9
10 namespace blink {
11
12 bool PaymentsValidators::isValidCurrencyCodeFormat(const String& code, String* o ptionalErrorMessage)
13 {
14 if (ScriptRegexp("^[A-Z]{3}$", TextCaseSensitive).match(code) == 0)
15 return true;
16
17 if (optionalErrorMessage)
18 *optionalErrorMessage = "'" + code + "' is not a valid ISO 4217 currency code, should be 3 upper case letters [A-Z]";
19
20 return false;
21 }
22
23 bool PaymentsValidators::isValidAmountFormat(const String& amount, String* optio nalErrorMessage)
24 {
25 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount) == 0)
26 return true;
27
28 if (optionalErrorMessage)
29 *optionalErrorMessage = "'" + amount + "' is not a valid ISO 20022 Curre ncyAnd30Amount";
30
31 return false;
32 }
33
34 bool PaymentsValidators::isValidRegionCodeFormat(const String& code, String* opt ionalErrorMessage)
35 {
36 if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0)
37 return true;
38
39 if (optionalErrorMessage)
40 *optionalErrorMessage = "'" + code + "' is not a valid ISO 3166 country code, should be 2 upper case letters [A-Z]";
41
42 return false;
43 }
44
45 bool PaymentsValidators::isValidLanguageCodeFormat(const String& code, String* o ptionalErrorMessage)
46 {
47 if (ScriptRegexp("^([a-z]{2,3})?$", TextCaseSensitive).match(code) == 0)
48 return true;
49
50 if (optionalErrorMessage)
51 *optionalErrorMessage = "'" + code + "' is not a valid ISO 639 language code, should be 2-3 lower case letters [a-z]";
52
53 return false;
54 }
55
56 bool PaymentsValidators::isValidScriptCodeFormat(const String& code, String* opt ionalErrorMessage)
57 {
58 if (ScriptRegexp("^([A-Z][a-z]{3})?$", TextCaseSensitive).match(code) == 0)
59 return true;
60
61 if (optionalErrorMessage)
62 *optionalErrorMessage = "'" + code + "' is not a valid ISO 1524 script c ode, should be an upper case letter [A-Z] followed by 3 lower case letters [a-z] ";
63
64 return false;
65 }
66
67 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698