How to validate form in Android

In this tutorial, you will learn how to validate form and show errors if something was missed. To validate form we'll use AwesomeValidation to declare validation style and add validations.

Add a following dependency in your project build

compile 'com.basgeekball:awesome-validation:1.3'

To display the error messages we need to define all the needed strings inside strings.xml file.

    <string name="name_required">Field name is requred</string>
    <string name="email_error">Enter a valid email</string>
    <string name="age_error">Enter a valid age</string>

To validate the input modify the code as below.

AwesomeValidation v;
EditText etName, etEmail, etAge;

protected void onCreate(Bundle savedInstanceState) {
    etName = (EditText) findViewById(;
    etEmail = (EditText) findViewById(;
    etAge = (EditText) findViewById(;
    v = new AwesomeValidation(ValidationStyle.BASIC);

    v.addValidation(this,, RegexTemplate.NOT_EMPTY, R.string.title_required);
    v.addValidation(this,, Patterns.EMAIL_ADDRESS, R.string.email_error);
    v.addValidation(this,, "^[1-150]{1,3}$", R.string.age_error);

private void submitForm() {
    if (v.validate()) {
        //process data 


comments powered by Disqus