Giter VIP home page Giter VIP logo

convalida's Introduction

Convalida Build Status codecov Android Arsenal API

Logo

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)
EditText nameField;

@LengthValidation(min = 3, errorMessage = R.string.min_3_characters)
EditText nickNameField;

@OnlyNumberValidation(R.string.only_numbers)
EditText ageField;

@EmailValidation(R.string.invalid_email)
EditText emailField;

@ConfirmEmailValidation(R.string.emails_not_match)
EditText confirmEmailField;

@PatternValidation(errorMessage = R.string.invalid_phone, pattern = PHONE_PATTERN)
EditText phoneField;

@PasswordValidation(min = 3, pattern = MIXED_CASE_NUMERIC, errorMessage = R.string.invalid_password)
EditText passwordField;

@ConfirmPasswordValidation(R.string.passwords_not_match)
EditText confirmPasswordField;

@ValidateOnClick
Button validateButton;

Step 2 - Initialize Convalida (notice that the it starts with the same name of the Activity):

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

Step 3 - Run the validations by clicking in the button mapped with @ValidateOnClick and handle success or error:

@OnValidationSuccess
public void onValidationSuccess() {
    Toast.makeText("Yay!", Toast.LENGTH_LONG).show();
}

@OnValidationError
public void onValidationError() {
    Toast.makeText("Something is wrong :(", Toast.LENGTH_LONG).show();
}

Note: Only the method annotated with @OnValidationSuccess is required.

Step 4 - If you want to clear the validations:

@ClearValidationsOnClick
Button clearValidationsButton;

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.3.7'
  annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:1.3.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.

convalida's People

Contributors

wellingtoncosta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.