forked from shihaam/thijooree
normaize account input
This commit is contained in:
@@ -256,7 +256,7 @@ class TransferFragment : Fragment() {
|
|||||||
Toast.makeText(requireContext(), R.string.transfer_select_source_first, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), R.string.transfer_select_source_first, Toast.LENGTH_SHORT).show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val accountNumber = binding.etTo.text?.toString()?.trim() ?: ""
|
val accountNumber = AccountInputParser.normalize(binding.etTo.text?.toString()?.trim() ?: "")
|
||||||
if (accountNumber.isBlank()) {
|
if (accountNumber.isBlank()) {
|
||||||
Toast.makeText(requireContext(), R.string.transfer_enter_account_first, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), R.string.transfer_enter_account_first, Toast.LENGTH_SHORT).show()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,6 +11,21 @@ object AccountInputParser {
|
|||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip spaces and remove a 960/+960 country code prefix, but only when
|
||||||
|
* the stripped result is exactly 7 digits (so "9603456" is left intact).
|
||||||
|
*/
|
||||||
|
fun normalize(input: String): String {
|
||||||
|
var s = input.replace(" ", "")
|
||||||
|
val stripped = when {
|
||||||
|
s.startsWith("+960") -> s.removePrefix("+960")
|
||||||
|
s.startsWith("960") -> s.removePrefix("960")
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
if (stripped != null && stripped.matches(Regex("^\\d{7}$"))) s = stripped
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
fun detect(input: String): InputType {
|
fun detect(input: String): InputType {
|
||||||
val s = input.trim()
|
val s = input.trim()
|
||||||
return when {
|
return when {
|
||||||
|
|||||||
Reference in New Issue
Block a user