-3

Is there a way to limit a text field so that it only accept certain letters from an array?

Let's say I have an array:

val array = arrayOf("a", "b", "c")

I want the list to be manipulated inside code, so that the letters you can type in the text field is changed by code. How do I implement this via a class to make it accept only the letters a, b, or c?

E_net4
  • 27,810
  • 13
  • 101
  • 139
HUAN5235
  • 13
  • 4

2 Answers2

1

Yes you can do this. In XML of edit text you need to use below code

android:digits="abc123"

Here abc123 are your required digits you want your edit text should accept. You can also limit to abc as your desire. So use below code

android:digits="abc"
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
0

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Pass whatever alphabets you want

Anita
  • 39
  • 1
  • 7