| 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 "wtf/text/StringImpl.h" | 8 #include "wtf/text/StringImpl.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 { | 24 { |
| 25 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount)
== 0) | 25 if (ScriptRegexp("^-?[0-9]+(\\.[0-9]+)?$", TextCaseSensitive).match(amount)
== 0) |
| 26 return true; | 26 return true; |
| 27 | 27 |
| 28 if (optionalErrorMessage) | 28 if (optionalErrorMessage) |
| 29 *optionalErrorMessage = "'" + amount + "' is not a valid ISO 20022 Curre
ncyAnd30Amount"; | 29 *optionalErrorMessage = "'" + amount + "' is not a valid ISO 20022 Curre
ncyAnd30Amount"; |
| 30 | 30 |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool PaymentsValidators::isValidRegionCodeFormat(const String& code, String* opt
ionalErrorMessage) | 34 bool PaymentsValidators::isValidCountryCodeFormat(const String& code, String* op
tionalErrorMessage) |
| 35 { | 35 { |
| 36 if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0) | 36 if (ScriptRegexp("^[A-Z]{2}$", TextCaseSensitive).match(code) == 0) |
| 37 return true; | 37 return true; |
| 38 | 38 |
| 39 if (optionalErrorMessage) | 39 if (optionalErrorMessage) |
| 40 *optionalErrorMessage = "'" + code + "' is not a valid ISO 3166 country
code, should be 2 upper case letters [A-Z]"; | 40 *optionalErrorMessage = "'" + code + "' is not a valid ISO 3166 country
code, should be 2 upper case letters [A-Z]"; |
| 41 | 41 |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 return true; | 59 return true; |
| 60 | 60 |
| 61 if (optionalErrorMessage) | 61 if (optionalErrorMessage) |
| 62 *optionalErrorMessage = "'" + code + "' is not a valid ISO 15924 script
code, should be an upper case letter [A-Z] followed by 3 lower case letters [a-z
]"; | 62 *optionalErrorMessage = "'" + code + "' is not a valid ISO 15924 script
code, should be an upper case letter [A-Z] followed by 3 lower case letters [a-z
]"; |
| 63 | 63 |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool PaymentsValidators::isValidShippingAddress(const mojom::blink::PaymentAddre
ssPtr& address, String* optionalErrorMessage) | 67 bool PaymentsValidators::isValidShippingAddress(const mojom::blink::PaymentAddre
ssPtr& address, String* optionalErrorMessage) |
| 68 { | 68 { |
| 69 if (!isValidRegionCodeFormat(address->region_code, optionalErrorMessage)) | 69 if (!isValidCountryCodeFormat(address->country, optionalErrorMessage)) |
| 70 return false; | 70 return false; |
| 71 | 71 |
| 72 if (!isValidLanguageCodeFormat(address->language_code, optionalErrorMessage)
) | 72 if (!isValidLanguageCodeFormat(address->language_code, optionalErrorMessage)
) |
| 73 return false; | 73 return false; |
| 74 | 74 |
| 75 if (!isValidScriptCodeFormat(address->script_code, optionalErrorMessage)) | 75 if (!isValidScriptCodeFormat(address->script_code, optionalErrorMessage)) |
| 76 return false; | 76 return false; |
| 77 | 77 |
| 78 if (address->language_code.isEmpty() && !address->script_code.isEmpty()) { | 78 if (address->language_code.isEmpty() && !address->script_code.isEmpty()) { |
| 79 if (optionalErrorMessage) | 79 if (optionalErrorMessage) |
| 80 *optionalErrorMessage = "If language code is empty, then script code
should also be empty"; | 80 *optionalErrorMessage = "If language code is empty, then script code
should also be empty"; |
| 81 | 81 |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |