Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow digits in BECS BSB and account number fields #2900

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.stripe.android.view

import android.content.Context
import android.text.InputFilter
import android.text.method.DigitsKeyListener
import android.text.InputType
import android.util.AttributeSet
import androidx.core.widget.doAfterTextChanged
import com.stripe.android.R
Expand Down Expand Up @@ -33,7 +33,7 @@ internal class BecsDebitAccountNumberEditText @JvmOverloads constructor(

init {
filters = arrayOf(InputFilter.LengthFilter(MAX_LENGTH))
keyListener = DigitsKeyListener.getInstance(false, true)
inputType = InputType.TYPE_CLASS_NUMBER

doAfterTextChanged {
shouldShowError = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.stripe.android.view
import android.content.Context
import android.text.Editable
import android.text.InputFilter
import android.text.method.DigitsKeyListener
import android.text.InputType
import android.util.AttributeSet
import com.stripe.android.R

Expand Down Expand Up @@ -50,7 +50,7 @@ internal class BecsDebitBsbEditText @JvmOverloads constructor(

init {
filters = arrayOf(InputFilter.LengthFilter(MAX_LENGTH))
keyListener = DigitsKeyListener.getInstance(false, true)
inputType = InputType.TYPE_CLASS_NUMBER

addTextChangedListener(
object : StripeTextWatcher() {
Expand All @@ -63,7 +63,7 @@ internal class BecsDebitBsbEditText @JvmOverloads constructor(
return
}

// skip formatting if past the separator
// skip formatting if past the separator
if (start > 4) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ class BecsDebitAccountNumberEditTextTest {
assertThat(accountNumberEditText.errorMessage)
.isNull()
}

@Test
fun `field should remove non-digits from input`() {
accountNumberEditText.append("212.121")
assertThat(accountNumberEditText.fieldText)
.isEqualTo("212121")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class BecsDebitBsbEditTextTest {
.isEqualTo("212121")
}

@Test
fun `field should remove non-digits from input`() {
bsbEditText.setText("212.121")
assertThat(bsbEditText.fieldText)
.isEqualTo("212-121")
}

@Test
fun bsb_whenError_updatesErrorrMessage() {
bsbEditText.bsb
Expand Down