Prevent duplicate numbers in SMS communicator config
This commit is contained in:
parent
b2bd2cafec
commit
0f4a428c00
2 changed files with 7 additions and 3 deletions
|
@ -1004,7 +1004,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
|
||||
private fun areMoreNumbers(allowednumbers: String?): Boolean {
|
||||
return allowednumbers?.let {
|
||||
var countNumbers = 0
|
||||
val knownNumbers = HashSet<String>()
|
||||
val substrings = it.split(";").toTypedArray()
|
||||
for (number in substrings) {
|
||||
var cleaned = number.replace(Regex("\\s+"), "")
|
||||
|
@ -1012,9 +1012,9 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
cleaned = cleaned.replace("+", "")
|
||||
cleaned = cleaned.replace("-", "")
|
||||
if (!cleaned.matches(Regex("[0-9]+"))) continue
|
||||
countNumbers++
|
||||
knownNumbers.add(cleaned)
|
||||
}
|
||||
countNumbers > 1
|
||||
knownNumbers.size > 1
|
||||
} ?: false
|
||||
}
|
||||
}
|
|
@ -7,9 +7,13 @@ class MultiPhoneValidator(val _customErrorMessage: String?) : Validator(_customE
|
|||
|
||||
override fun isValid(editText: EditText): Boolean {
|
||||
val substrings = editText.text.split(";").toTypedArray()
|
||||
val knownNumbers = HashSet<String>()
|
||||
for (number in substrings) {
|
||||
if (!PatternValidator(_customErrorMessage, Patterns.PHONE).isValid(number))
|
||||
return false
|
||||
if (knownNumbers.contains(number))
|
||||
return false
|
||||
knownNumbers.add(number)
|
||||
}
|
||||
return substrings.isNotEmpty()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue