I have an issue in validating edit text in my android application. I have tried many methods and none of them are suiting my scenario. When user tries to save the post the entering only spaces in edit text field I need to pop out an error message. But I am able to check the condition where user enters only spaces.
I have used the following methods:
if(subjectText.isEmpty() || detailsText.isEmpty() || subjectText.equals(" ") || detailsText.equals(" ")){
// perform operation.
}
Here the .equals(" ")
method checks only for one space. If the user entry is some thing like " "
and not text, how can I check tell the user there is not text. Please any one let me know. All suggestions are welcome.
I have also tried with .contains(" ")
method, this method solves the problem but even if there is space in between text it pops the error which should not happen. If the user entry is "how are you"
, the .contains(" ")
method give an error.
How can I solve this issue. Please help me come out of this issue.