Originally posted by Gopu Akraju:
String name = nameTextField.getText();
name.trim();
if(name == null || name == (" ") || name.length() ==0 || name ==("\\s")){
//Stop the user
}
String.trim() doesn't do what you think it does.
Strings are immutable. Try
name = name.trim() instead. In that case:
a)
name == null can't be true or else name.trim() would have thrown NullPointerException.
b)
name == (" ") can't be true because it has been trim()ed.
c)
name.length() ==0 is valid and is all you really need.
d)
name ==("\\s") is
testing for the literal name
\s. The == operator has nothing to do with regular expressions. See
String.
matches().
[ April 17, 2008: Message edited by: Brian Cole ]