| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/payments/PaymentsValidators.h" | 5 #include "modules/payments/PaymentsValidators.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptRegexp.h" | 7 #include "bindings/core/v8/ScriptRegexp.h" |
| 8 #include "platform/weborigin/KURL.h" | 8 #include "platform/weborigin/KURL.h" |
| 9 #include "platform/wtf/text/StringImpl.h" | 9 #include "platform/wtf/text/StringImpl.h" |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return true; | 41 return true; |
| 42 | 42 |
| 43 if (optional_error_message) | 43 if (optional_error_message) |
| 44 *optional_error_message = | 44 *optional_error_message = |
| 45 "The currency code should be at most 2048 characters long"; | 45 "The currency code should be at most 2048 characters long"; |
| 46 | 46 |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool PaymentsValidators::IsValidAmountFormat(const String& amount, | 50 bool PaymentsValidators::IsValidAmountFormat(const String& amount, |
| 51 const String& item_name, |
| 51 String* optional_error_message) { | 52 String* optional_error_message) { |
| 52 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", kTextCaseSensitive) | 53 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", kTextCaseSensitive) |
| 53 .Match(amount) == 0) | 54 .Match(amount) == 0) |
| 54 return true; | 55 return true; |
| 55 | 56 |
| 56 if (optional_error_message) | 57 if (optional_error_message) { |
| 57 *optional_error_message = "'" + amount + "' is not a valid amount format"; | 58 *optional_error_message = |
| 59 "'" + amount + "' is not a valid amount format for " + item_name; |
| 60 } |
| 58 | 61 |
| 59 return false; | 62 return false; |
| 60 } | 63 } |
| 61 | 64 |
| 62 bool PaymentsValidators::IsValidCountryCodeFormat( | 65 bool PaymentsValidators::IsValidCountryCodeFormat( |
| 63 const String& code, | 66 const String& code, |
| 64 String* optional_error_message) { | 67 String* optional_error_message) { |
| 65 if (ScriptRegexp("^[A-Z]{2}$", kTextCaseSensitive).Match(code) == 0) | 68 if (ScriptRegexp("^[A-Z]{2}$", kTextCaseSensitive).Match(code) == 0) |
| 66 return true; | 69 return true; |
| 67 | 70 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return true; | 137 return true; |
| 135 | 138 |
| 136 if (optional_error_message) | 139 if (optional_error_message) |
| 137 *optional_error_message = | 140 *optional_error_message = |
| 138 "Error message should be at most 2048 characters long"; | 141 "Error message should be at most 2048 characters long"; |
| 139 | 142 |
| 140 return false; | 143 return false; |
| 141 } | 144 } |
| 142 | 145 |
| 143 } // namespace blink | 146 } // namespace blink |
| OLD | NEW |