How to restrict the user to enter leading, trailing and consecutive space in a string in kotlin

186 views Asked by At

I have a scenario, where I need to restrict the user to enter leading, trailing and consecutive space and if the user enters do not update the text with space but show the error message.

Its like not updating the text itself when user enters any of the leading, trailing or consecutive spaces.

How can we do that in kotlin?

1

There are 1 answers

1
Ömer Seyfettin Yavuzyiğit On

If you don't want leading and trailing blanks you can use trim()

eg: editText.text.trim.toString.trim()