Implemented validating max length of remittee name and usage

This commit is contained in:
dankito 2020-05-14 14:50:58 +02:00
parent deb7f3ad36
commit d32bb7d167
4 changed files with 44 additions and 4 deletions

View File

@ -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())
}
}

View File

@ -92,6 +92,7 @@
<string name="error_no_name_entered">Bitte geben Sie den Namen des Empfängers ein</string>
<string name="error_entered_name_too_long">Name darf nur 70 Zeichen lang sein</string>
<string name="error_invalid_sepa_characters_entered">Unzulässige(s) Zeichen eingegeben: %s</string>
<string name="error_no_iban_entered">Bitte geben Sie die IBAN des Empfängers ein</string>
<string name="error_invalid_iban_characters_entered">Unzulässige(s) Zeichen eingegeben: %s</string>
@ -102,5 +103,6 @@
<string name="error_invalid_bic_pattern_entered">Eine BIC besteht aus 8 oder 11 Zeichen und folgt dem Muster: ABCDED12(XYZ)</string>
<string name="error_no_amount_entered">Bitte geben Sie den zu überweisenden Betrag ein</string>
<string name="error_invalid_amount_entered">Bitte geben Sie einen Betrag größer 0 ein.</string>
<string name="error_entered_usage_too_long">Verwendungszweck darf nur 140 Zeichen lang sein</string>
</resources>

View File

@ -92,6 +92,7 @@
<string name="error_no_name_entered">Please enter remittee\'s name</string>
<string name="error_entered_name_too_long">Name may only have 70 characters</string>
<string name="error_invalid_sepa_characters_entered">Invalid character(s) entered: %s</string>
<string name="error_no_iban_entered">Please enter remittee\'s IBAN</string>
<string name="error_invalid_iban_characters_entered">Invalid character(s) entered: %s</string>
@ -102,5 +103,6 @@
<string name="error_invalid_bic_pattern_entered">A BIC consists of 8 or 11 characters and has the pattern: ABCDED12(XYZ)</string>
<string name="error_no_amount_entered">Please enter the amount to be transferred</string>
<string name="error_invalid_amount_entered">Please enter an amount greater zero.</string>
<string name="error_entered_usage_too_long">Usage may only have 140 characters</string>
</resources>

View File

@ -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)
}