PDA

View Full Version : whitespace and strings


Yui
10-22-2008, 02:54 PM
ok, this is rather frustrating cause i know it's simple, but i can't seem to get it right.

i have this multiline text input, and i need to detect if the user typed anything (anything besides white space) - when he hits the "enter" key. the string in the input text is only valid if there's at least 1 char that's not whitespace.

i tried the following function to validate the string, but it's not really working (the function returns "true" when theres a newline in the input text) :confused:

function validateMessage(message:String):Boolean
{
if (message == "") return false;

for (var i:uint = 0; i < message.length; i++)
{
if (message.charAt(i) != " " && message.charAt(i) != "\n")
{
return true;
}
}
return false;
}