diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2Fragment.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2Fragment.kt index d7c1c7e1c5..7002d5e402 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2Fragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2Fragment.kt @@ -186,8 +186,11 @@ class EnterPhoneNumberV2Fragment : LoggingFragment(R.layout.fragment_registratio private fun initializeInputFields() { binding.countryCode.editText?.addTextChangedListener { s -> - val countryCode: Int = s.toString().toInt() - fragmentViewModel.setCountry(countryCode) + val sanitized = s.toString().filter { c -> c.isDigit() } + if (sanitized.isNotNullOrBlank()) { + val countryCode: Int = sanitized.toInt() + fragmentViewModel.setCountry(countryCode) + } } phoneNumberInputLayout.addTextChangedListener { diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2ViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2ViewModel.kt index 6ddf80c906..475ebae7a6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2ViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/v2/ui/phonenumber/EnterPhoneNumberV2ViewModel.kt @@ -63,6 +63,11 @@ class EnterPhoneNumberV2ViewModel : ViewModel() { fun setCountry(digits: Int) { val matchingIndex = countryCodeToAdapterIndex(digits) + if (matchingIndex == -1) { + Log.d(TAG, "Invalid country code specified $digits") + return + } + store.update { it.copy(countryPrefixIndex = matchingIndex) }