Convalida

Additional

Language
Java
Version
1.0.7 (Nov 19, 2017)
Created
Jun 6, 2017
Updated
Nov 20, 2017
Owner
Wellington Costa Pereira (WellingtonCosta)
Contributor
Wellington Costa Pereira (WellingtonCosta)
1
Activity
Badge
Generate
Download
Source code

Announcement

Convalida

Convalida - (Italian for "validation")

Convalida is a simple, lightweight and powerful field validation library for Android.

Why Convalida?

Quick Start

Step 1 - Annotate your fields with Convalida Annotations:

@NotEmptyValidation(R.string.field_required)
TextInputLayout nameLayout;

@LengthValidation(min = 3, errorMessage = R.string.min_3_characters)
TextInputLayout nickNameLayout;

@OnlyNumberValidation(R.string.only_numbers)
TextInputLayout ageLayout;

@EmailValidation(R.string.invalid_email)
TextInputLayout emailLayout;

@PatternValidation(errorMessage = R.string.invalid_phone, pattern = PHONE_PATTERN)
TextInputLayout phoneLayout;

@PasswordValidation(min = 3, pattern = LOWER_UPPER_CASE_NUMERIC, errorMessage = R.string.invalid_password)
TextInputLayout passwordLayout;

@ConfirmPasswordValidation(R.string.passwords_not_match)
TextInputLayout confirmPasswordLayout;

Step 2 - Initialize Convalida:

private ConvalidaValidator validator;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    validator = Convalida.init(this);
}

Step 3 - Run the validations and get the result:

public void validateFields() {
    boolean isValid = validator.validateFields();
    String message = isValid ? "Yay!" : "Something is wrong :(";
    Snackbar.make(linearLayout, message, Snackbar.LENGTH_LONG).show();
}

Step 4 - If you want to clear the validations:

public void clearFields() {
    validator.clearValidations();
}

Remember: You must initialize the views (e.g ButterKnife) before apply the validations.

Download

Step 1 - Add the JitPack repository to your root build.gradle file:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2 - Add the dependencies:

dependencies {
  compile 'com.github.WellingtonCosta.convalida:convalida:1.0.7'
  annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:1.0.7'
}

License

Copyright 2017 Wellington Costa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.