EF's Blog

Android Tutorial : Check/Validate Empty EditText

Posted on: May 11, 2012

I create this method

public static boolean isNotEmptyValidator (String strValue,int intMinLength)
{
if(strValue.length() < intMinLength)
return false;
else
return true;
}

and use this to use it:

EditText etEmail = (EditText)findViewById(R.id.etContactEmail);
EditText etNama= (EditText)findViewById(R.id.etContactNama);

String strErrorMsg = “”, strEmailContent =””;
boolean boolValid = true;

if(boolValid == true)
{
if(validator.isNotEmptyValidator(etEmail.getText().toString(), 11))
{
strErrorMsg += “Email tidak boleh kosong dan harus memiliki format email yang benar. (contoh : cs@sinarmasmsiglife.co.id).\n”;
boolValid = false;
if(validator.emailValidator(etEmail.getText().toString()) == false)
{
strErrorMsg = “Format Email tidak benar. (contoh format email yang benar: cs@sinarmasmsiglife.co.id)”;
}
}
if(validator.isNotEmptyValidator(etNama.getText().toString(), 3))
{
strErrorMsg += “Nama tidak boleh kosong dan minimal 3 karakter.\n”;
boolValid = false;
}

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

EF’s Blog

I'm just ordinary people who lived in an extra-ordinary world.

EF's Blog Stats

  • 126,562 hits
May 2012
M T W T F S S
« Apr   Jul »
 123456
78910111213
14151617181920
21222324252627
28293031  

Archives

%d bloggers like this: