Hey, I want to restrict zero at the beginning of text input when the user type. So How it would be possible to restrict to enter zero at the be beginning, but the user can enter in the middle of the text.
For example
Not enter Zero at beginning
Copy code
0111 user will not allow displaying in edit text. only 111 is allowed
Allow zero at middle
Copy code
1101 it can allow zero in middle.
😶 4
r
Rahul Rawat
11/22/2021, 3:02 PM
Try using a custom input filter inside which you can check if the entered string contains zero at start or not and prevent entering it
v
Vivek Modi
11/22/2021, 3:05 PM
Can you give me example please how?
r
rook
11/22/2021, 4:43 PM
This isn’t Kotlin related, but
EditText
can have
onTextChanged
listeners attached to it. I’d use that along with
String.first() == '0'
to solve your problem.
e
ephemient
11/22/2021, 10:46 PM
it can be trickier: what if the user enters 100, then deletes the 1
ephemient
11/22/2021, 10:47 PM
but yeah, just use existing Android APIs, nothing Kotlin specific about them