OLD | NEW |
(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 isValidCurrencyCodeFormat(const String& code, String* optionalErrorMessage) |
| 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 isValidAmountFormat(const String& amount, String* optionalErrorMessage) |
| 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 isValidRegionCodeFormat(const String& code, String* optionalErrorMessage) |
| 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 isValidLanguageCodeFormat(const String& code, String* optionalErrorMessage) |
| 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 isValidScriptCodeFormat(const String& code, String* optionalErrorMessage) |
| 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 |
OLD | NEW |