From d32bb7d1676d60e6e685899dbe793b5457adadf4 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 14 May 2020 14:50:58 +0200 Subject: [PATCH] Implemented validating max length of remittee name and usage --- .../android/ui/dialogs/TransferMoneyDialog.kt | 15 +++++++--- .../src/main/res/values-de/strings.xml | 2 ++ .../src/main/res/values/strings.xml | 2 ++ .../dankito/banking/util/InputValidator.kt | 29 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt index d8ccfe02..6cd5e7a1 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt @@ -322,6 +322,9 @@ open class TransferMoneyDialog : DialogFragment() { if (enteredName.isEmpty()) { lytRemitteeName.error = context?.getString(R.string.error_no_name_entered) } + else if (inputValidator.hasRemitteeNameValidLength(enteredName) == false) { + lytRemitteeName.error = context?.getString(R.string.error_entered_name_too_long) + } else { lytRemitteeName.error = context?.getString( R.string.error_invalid_sepa_characters_entered, inputValidator.getInvalidSepaCharacters(enteredName)) @@ -332,8 +335,7 @@ open class TransferMoneyDialog : DialogFragment() { protected open fun isRemitteeNameValid(): Boolean { val enteredRemitteeName = edtxtRemitteeName.text.toString() - return enteredRemitteeName.isNotEmpty() - && inputValidator.containsOnlyValidSepaCharacters(enteredRemitteeName) + return inputValidator.isRemitteeNameValid(enteredRemitteeName) } protected open fun checkIfEnteredRemitteeIbanIsValid() { @@ -426,17 +428,22 @@ open class TransferMoneyDialog : DialogFragment() { } protected open fun checkIfEnteredUsageTextIsValid() { + val enteredUsage = edtxtUsage.text.toString() + if (isUsageTextValid()) { lytUsage.error = null } + else if (inputValidator.hasUsageValidLength(enteredUsage) == false) { + lytUsage.error = context?.getString(R.string.error_entered_usage_too_long) + } else { lytUsage.error = context?.getString(R.string.error_invalid_sepa_characters_entered, - inputValidator.getInvalidSepaCharacters(edtxtUsage.text.toString())) + inputValidator.getInvalidSepaCharacters(enteredUsage)) } } protected open fun isUsageTextValid(): Boolean { - return inputValidator.containsOnlyValidSepaCharacters(edtxtUsage.text.toString()) + return inputValidator.isUsageValid(edtxtUsage.text.toString()) } } \ No newline at end of file diff --git a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml index ed9e94cf..12cf5284 100644 --- a/ui/BankingAndroidApp/src/main/res/values-de/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values-de/strings.xml @@ -92,6 +92,7 @@ Bitte geben Sie den Namen des Empfängers ein + Name darf nur 70 Zeichen lang sein Unzulässige(s) Zeichen eingegeben: %s Bitte geben Sie die IBAN des Empfängers ein Unzulässige(s) Zeichen eingegeben: %s @@ -102,5 +103,6 @@ Eine BIC besteht aus 8 oder 11 Zeichen und folgt dem Muster: ABCDED12(XYZ) Bitte geben Sie den zu überweisenden Betrag ein Bitte geben Sie einen Betrag größer 0 ein. + Verwendungszweck darf nur 140 Zeichen lang sein diff --git a/ui/BankingAndroidApp/src/main/res/values/strings.xml b/ui/BankingAndroidApp/src/main/res/values/strings.xml index 493d9da5..63b6905c 100644 --- a/ui/BankingAndroidApp/src/main/res/values/strings.xml +++ b/ui/BankingAndroidApp/src/main/res/values/strings.xml @@ -92,6 +92,7 @@ Please enter remittee\'s name + Name may only have 70 characters Invalid character(s) entered: %s Please enter remittee\'s IBAN Invalid character(s) entered: %s @@ -102,5 +103,6 @@ A BIC consists of 8 or 11 characters and has the pattern: ABCDED12(XYZ) Please enter the amount to be transferred Please enter an amount greater zero. + Usage may only have 140 characters diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt index d36c1a5d..df682dde 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt @@ -9,6 +9,11 @@ open class InputValidator { companion object { + const val RemitteNameMaxLength = 70 + + const val UsageMaxLength = 140 + + /** * The IBAN consists of up to 34 alphanumeric characters, as follows: * - country code using ISO 3166-1 alpha-2 – two letters, @@ -73,6 +78,30 @@ open class InputValidator { } + open fun isRemitteeNameValid(stringToTest: String): Boolean { + val convertedString = convertToAllowedSepaCharacters(stringToTest) + + return hasRemitteeNameValidLength(convertedString) + && containsOnlyValidSepaCharacters(convertedString) + } + + open fun hasRemitteeNameValidLength(stringToTest: String): Boolean { + return stringToTest.length in 1..RemitteNameMaxLength + } + + + open fun isUsageValid(stringToTest: String): Boolean { + val convertedString = convertToAllowedSepaCharacters(stringToTest) + + return hasUsageValidLength(convertedString) + && containsOnlyValidSepaCharacters(convertedString) + } + + open fun hasUsageValidLength(stringToTest: String): Boolean { + return stringToTest.length in 0..UsageMaxLength // usage is not a required field -> may be empty + } + + open fun containsOnlyValidSepaCharacters(stringToTest: String): Boolean { return sepaMessageCreator.containsOnlyAllowedCharacters(stringToTest) }