I have a UITextField where user can enter a name and save it. But, user should not be allowed to enter blank spaces in the textFiled.
1 – How can I find out,if user has entered two blank spaces or complete blank spaces in the textFiled
2 – How can i know if the textFiled is filled only with blank spaces
edit – It is invalid to enter only white spaces(blank spaces)
You can “trim” the text, that is remove all the whitespace at the start and end. If all that’s left is an empty string, then only whitespace (or nothing) was entered.
If you want to check whether there is any whitespace (anywhere in the text), you can do it like this:
If you want to prevent the user from entering whitespace at all, see @Hanon’s solution.