Android EditText Validation Example

      Comments Off on Android EditText Validation Example

Android EditText Validation Example

Android EditText Validation Example

Android EditText Validation Example explains how you can add validation to your EditText Control of android. The important feature of this android tutorial is that it’s only 1 line to validate EditText text. Here I have prepared the tutorial for validating Blank Text Box Validation, Email Address Validation, Website Validation.

Also check out Android Spinner Example.

Career skills to jumpstart your future.Sample Code

// Validation for Blank Field
if(et1.getText().toString().length()==0)
{
     Toast.makeText(getApplicationContext(), “Name cannot be Blank”, Toast.LENGTH_LONG).show();
     et1.setError(“Name cannot be Blank”);
     return;
}
else if(!android.util.Patterns.EMAIL_ADDRESS.matcher(et2.getText().toString()).matches())
{
     // Validation for Invalid Email Address
     Toast.makeText(getApplicationContext(), “Invalid Email”, Toast.LENGTH_LONG).show();
     et2.setError(“Invalid Email”);
     return;
}
else if(!android.util.Patterns.DOMAIN_NAME.matcher(et3.getText().toString()).matches())
{
     // Validation for Website Address
     Toast.makeText(getApplicationContext(), “Invalid Website”, Toast.LENGTH_LONG).show();
     et3.setError(“Invalid Website”);
     return;
}
else
{
Toast.makeText(getApplicationContext(), “Validated Succesfully”,     Toast.LENGTH_LONG).show();
}

Output 1

Android EditText Validation Example

Output 2

Android EditText Validation Example

Output 3

Android EditText Validation Example

Output 4

Android EditText Validation Example

Output 5

Android EditText Validation Example

Above screenshot of the android app shows working of EditText Validation using native android development. If you think I am missing something please let me know using contact us form.

If you are looking for any other tutorial click on the respected Menu Items. I have written tutorial on C, DBMS, HTML, PHP, Android and many more.All tutorials are with Example and Step by Step Guide.

PS:
If you like my article, Please share with your friends on Facebook, WhatsApp, Twitter, etc. Thanks in Advance.

Save