Reputation: 63
var sample:String = filterBox.text;
Based on the String I get from TextInput, a Button has to be disabled if the String has only white spaces and enabled only otherwise.
I want to check if the String has only white spaces.
Is/Are there any inbuilt methods in flex for this? I saw some answers for Java to use trim method. But its not available in Flex. Please help me out.
Upvotes: 0
Views: 628
Reputation: 7294
Using
private const r:RegExp = /\S/;
private function isEmpty(str:String):Boolean {
return = !r.test(str);
}
then
trace(isEmpty("hello world")); //false
trace(isEmpty(" ")); //true
trace(isEmpty(" ")); //true
Upvotes: 2
Reputation: 6566
You can do the following
StringUtil.trim(string);
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html
String has a lot of methods which match for patterns you can find it here. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html
Upvotes: 2