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

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?



Solution 1:[1]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ă–mer Seyfettin Yavuzyi?it