EF's Blog

Posts Tagged ‘checker

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;
}

public static boolean emailValidator(String strEmail) {
boolean isValid = false;

String expression = “^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$”;
CharSequence inputStr = strEmail;

Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}


EF’s Blog

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

EF's Blog Stats

  • 137,304 hits
August 2017
M T W T F S S
« Jul    
 123456
78910111213
14151617181920
21222324252627
28293031  

Archives