On my ongoing project,I allow user to add text to the application.Once the user presses the “Add Button” on my app,an input text field is added along with user input.
So,I needed to check whether the user input is empty or not.I googled and found some solution.But when I used it ,they weren’t the effective ones.
//the solution were like this
//then perform some action
//alert user that input text is empty
These two method works well when user doesn’t input anything and clicks the add button.But if the user do the following
The user just presses spaces or spacebar and then press add button
The user writes something and then deletes all of it and presses space
Then both of above logic to find empty input fails.
So I again googled for some String utility classes and finally found one
which contained a method called trimWhiteSpace.
This method does is replaces all the whiteSpace or say spaces of the input text and returns the length of the text without white space.
So this method proved to be the best for finding out the empty input on text field.
function trimWhiteSpace(source:String) :uint
var pattern:RegExp = /[\s]+/g;
//alert user for empty input
Hope this helps for all to find out whether the input text is empty or not