Android EditText validations

Android EditText can be validated much easily see the below example:

EditText loginText = (EditText)this.findViewById(;

Integer nameLen = 8;

int len = loginText.length();
if (len<=0) {
else if (len< nameLen) {
loginText.setError(getString(R.string.error_character_length, nameLen));
else {
nameId = loginText.getText().toString();



Filed under Uncategorized

8 responses to “Android EditText validations

  1. Pingback: Check for empty Edittext - Android Forums

  2. Doreamon

    Thanks phaniraghav for your sharing,

    Could you show us how to trigger the error, the onFocusChanged event doesn’t perform when pressing in the login button.

  3. i have spent so much time trying multiple things people recommend [including your example] – nothing so far! can you help? my code:

    amount1=(EditText)findViewById(;//field where input entered
    [upon pressing calculate button/in private void calculate()]:
    int len = strAmount1.length();
    if (len == 0) {
    Toast.makeText(getApplicationContext(), “PROBLEMS”, Toast.LENGTH_LONG).show();
    else {
    Toast.makeText(getApplicationContext(), “THINGS OK”, Toast.LENGTH_LONG).show();
    i have tried numerous things, including .isEmpty, isEqual(“”) – all without syntax error, but it is as if it ignores the test, and it just app.crashes:P. help??!

  4. bhavna

    Very Helpfull Post,,,,
    grt 🙂

  5. A person necessarily assist to make critically articles I’d state. This is the very first time I frequented your web page and up to now? I surprised with the analysis you made to make this actual publish extraordinary. Great process!

  6. Nice blog right here! Additionally your web site so much up fast! What host are you using? Can I am getting your affiliate link for your host? I want my web site loaded up as fast as yours lol

  7. dubbellu

    Thx, I searched the net for this!!!!
    it works perfect for my little project (Learning Android from basics).

    Thx again 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s