Android: need to validate an edittext for non-blank input

Anne Gunn picture Anne Gunn · Apr 22, 2010 · Viewed 14.8k times · Source

If I want to enforce a maximum length of input in an EditText field, I can use the maxLength attribute. But if I want to enforce a minimum length (in my case, simply non-blank), I find no corresponding minLength attribute.

I've also looked at the various 'inputType' attributes (phone, password, etc) but I don't see anything like 'required' or 'non-blank'.

I can't believe this would require a custom input filter; it's more likely the answer is so obvious it just doesn't get written down in the form I'm asking the question.

Answer

jqpubliq picture jqpubliq · Apr 22, 2010

You can simply check that yourField.text() is not equivalent to null or "" at the point of submission. If it is, prompt the user to input something.