A simple library for validating user input in forms using annotations.

Overview

ValidationKomensky for Android

A simple library for validating user input in forms using annotations.

alt text

Features:

  • Validate all views at once and show feedback to user. With one line of code.
  • Live validation - check user input as he moves between views with immediate feedback.
  • Extensible library - you can add your own validations or adapters for custom views.

How to include it in your project:

With Gradle:

compile 'eu.inmite.android.lib:android-validation-komensky:[email protected]'

Manually:

  • clone the project
  • add it as library project in your IDE

How to validate

First, annotate your views like this:

@NotEmpty(messageId = R.string.validation_name)
@MinLength(value = 3, messageId = R.string.validation_name_length, order = 2)
private EditText mNameEditText;

Now you are ready to:

FormValidator.validate(this, new SimpleErrorPopupCallback(this));

You will receive collection of all failed validations in a callback and you can present them to the user as you want. Or simply use prepared callbacks (like SimpleErrorPopupCallback).

Live validation

To start and stop live validation, simply call:

FormValidator.startLiveValidation(this, new SimpleErrorPopupCallback(this));
FormValidator.stopLiveValidation(this);

List of all supported validation annotations

Validations supported out of the box:

@NotEmpty(messageId = R.string.validation_name, order = 1)
private EditText mNameEditText;
@MinLength(value = 1, messageId = R.string.validation_participants, order = 2)
private EditText mNameEditText;
@MinValue(value = 2L, messageId = R.string.validation_name_length)
private EditText mEditNumberOfParticipants;
@MinNumberValue(value = "5.5", messageId = R.string.validation_name_length)
private EditText mEditPotentialOfHydrogen;
@RegExp(value = EMAIL, messageId = R.string.validation_valid_email)
private EditText mEditEmail;
@RegExp(value = "^[0-9]+$", messageId = R.string.validation_valid_count)
private EditText mEditCount;
@DateInFuture(messageId = R.string.validation_date)
private TextView mTxtDate;
@DateNoWeekend(messageId = R.string.validation_date_weekend)
private TextView mTxtDate;
@Custom(value = MyVeryOwnValidator.class, messageId = R.string.validation_custom)
private EditText mNameEditText;

Proguard

Should you need to use the proguard, copy these rules:

-keepattributes *Annotation*
-keep class eu.inmite.android.lib.validations.form.annotations.** { *; }
-keep class * implements eu.inmite.android.lib.validations.form.iface.ICondition
-keep class * implements eu.inmite.android.lib.validations.form.iface.IValidator
-keep class * implements eu.inmite.android.lib.validations.form.iface.IFieldAdapter
-keepclassmembers class ** {
	@eu.inmite.android.lib.validations.form.annotations.** *;
}

Why 'Komensky'?

Jan Ámos Komenský was a famous Czech educator, father of modern education methods.  Teachers tend to correct you, just like this library. You won't miss any errors in the user input.

See our other Czech personalities who help with #AndroidDev.

Comments
  • Gradle support with smart validations addition

    Gradle support with smart validations addition

    For such (very common) situations: login validations

    See, you have to manage validation status of fields independently – but now, you can do it with single validation callback just in one place.

    Here is code sample: https://gist.github.com/almozavr/d13bb2561afff6c5a870

    opened by almozavr 8
  • Change Calendar.HOUR to Calendar.HOUR_OF_DAY

    Change Calendar.HOUR to Calendar.HOUR_OF_DAY

    Because in regions where it works with 24h, using cal.set(Calendar.HOUR, 0) can happen to set as 12AM instead of 12PM.

    Like this:

    I/System.out﹕ Tue Aug 25 12:00:00 BRT 2015
    

    The correct would be:

    I/System.out﹕ Tue Aug 25 00:00:00 BRT 2015
    
    opened by douglasjunior 4
  • Proguard issue

    Proguard issue

    Hi, I used this library and after I enabled Proguard my app crashes while validation process. It occures in CustomValidator.validate(). What are rules for Proguard for this library?

    opened by IlyaEremin 4
  • build failed upon adding library

    build failed upon adding library

    As soon as I add

    compile 'eu.inmite.android.lib:android-validation-komensky:0.9.2'

    in my gradle and build it , it gives this error:

    Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: E:\Aman\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output E:\Aman\Workspace\I2I\app\build\intermediates\dex\debug --input-list=E:\Aman\Workspace\I2I\app\build\intermediates\tmp\dex\debug\inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106)

    I dont know why this error or which other library it is conflicting with, So I here are other libraries in my project:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile 'com.android.support:recyclerview-v7:21.0.3'
        compile 'com.android.support:cardview-v7:21.0.3'
        compile 'com.google.android.gms:play-services-location:6.5.87'
    
        compile 'com.squareup.okhttp:okhttp:2.1.0'
        compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
        compile 'com.squareup.retrofit:retrofit:1.8.0'
        compile 'com.jakewharton:butterknife:6.0.0'
        compile 'com.google.code.gson:gson:2.3.1'
    
        compile 'com.nispok:snackbar:2.5.2'
        compile 'eu.inmite.android.lib:android-validation-komensky:0.9.2'
    
    
    }
    
    opened by Aexyn 4
  • Build failed with the latest Gradle

    Build failed with the latest Gradle

       compile 'com.android.support:support-v4:+'
       compile 'eu.inmite.android.lib:android-validation-komensky:0.9.2'
    

    will fail 'cause of

    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
    </dependency>
    

    missing provided?

    Error:

    Error:Execution failed for task ':apps:sample:dexDebug'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        /Applications/Android Studio.app/android-sdk-macosx/build-tools/19.0.3/dx --dex ...
    
        UNEXPECTED TOP-LEVEL EXCEPTION:
        com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
            at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
            at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
            at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
            at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
            at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
            at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
            at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
            at com.android.dx.command.dexer.Main.run(Main.java:230)
            at com.android.dx.command.dexer.Main.main(Main.java:199)
            at com.android.dx.command.Main.main(Main.java:103)
    
    opened by almozavr 4
  • Change Calendar.HOUR to Calendar.HOUR_OF_DAY

    Change Calendar.HOUR to Calendar.HOUR_OF_DAY

    Because in regions where it works with 24h, using cal.set(Calendar.HOUR, 0) can happen to set as 12AM instead of 12PM.

    Like this:

    I/System.out﹕ Tue Aug 25 12:00:00 BRT 2015
    

    The correct would be:

    I/System.out﹕ Tue Aug 25 00:00:00 BRT 2015
    
    opened by douglasjunior 3
  • Support v4 causes DEX errors when including library into build

    Support v4 causes DEX errors when including library into build

    I probably have a different version of support v4 that is coming from the support:v7 package which i cannot change. is support:v4 needed for the library?

    opened by darko1002001 3
  • Strange behavior of validateSingleView(...)

    Strange behavior of validateSingleView(...)

    When a single view validation has succeeded, I don't want to have an all target (which can be potentially an activity or a fragment) validation that makes no sense if I had chosen to validate only a single view in the target.

    opened by Narayane 2
  • Adding @FieldsEqual validation annotation

    Adding @FieldsEqual validation annotation

    I thought this annotation would be useful for forms where one or more fields need to be equal (i.e. password/confirm password).

    There is a "fields" property on the annotation where you provide an array of the other field ids that must be equal to the annotated field for validation to pass.

    Let me know if you want unit tests included before accepting the PR.

    opened by creativedrewy 2
  • Project Unmaintained?

    Project Unmaintained?

    It looks pretty much that this library got some issues and is no longer maintained. Who is actively using this? Who is satisfied? Also there are more than 50 forks of this project? Is there any more active version?

    opened by mindrunner 2
  • use with float label text

    use with float label text

    How can I use this with float label text library,where the view is not actually edittext ? The edittext is wrapped inside a Layout. For ex: https://github.com/hardik-trivedi/FloatingLabel

    opened by Krishan14sharma 2
  • @MaxValue not working properly

    @MaxValue not working properly

    Hello dear creator of this cool library tool. At first I want say thank you about so good library and economy time developers like I'm.

    But I have problem, with MaxValue anotation:

        @BindView(R.id.fuel_level_large)
        @MaxValue(value = EDIT_TEXT_MAX_VALUE, messageId = R.string.max_number_32767, order = 1)
        EditText fuelLevelLarge;
    

    In this case, checking return false for empty editText, but there can't be more than EDIT_TEXT_MAX_VALUE, because this field is empty. How I can fix this issue, please help me.

    Also please help me understand how I can change color of some elements in error popup dialog.

    Thank you.

    opened by smail2133 0
  • Can't run the project in Android Studio

    Can't run the project in Android Studio

    I downloaded the project and opened it using Android Studio. Then I updated classpath 'com.android.tools.build:gradle:3.0.1' distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip and I make such a mistake. How can I fix it?

    Error:Manifest Tasks does not support the manifestOutputFile property any more, please use the manifestOutputDirectory instead. For more information, please check https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

    opened by TikTak123 0
  • Validating Password and confirm password fields

    Validating Password and confirm password fields

    I tried to use this library for validating a signup form which has two fields namely Password and Confirm password. can anyone tell me how to apply validation and be sure that both contain the same values.??

    opened by Agrahyah 0
  • Jitpack integration failed

    Jitpack integration failed

    I try to get the master branch updated code (with my pull request) as a gradle dependency thanks to jitpack.io into my android studio project.

    I have tried:

    • compile 'com.github.inmite:android-validation-komensky:7c544f2'
    • compile 'com.github.inmite:android-validation-komensky:master-SNAPSHOT'

    But nothing works... (FYI)

    How can I get the latest code version of your master branch without waiting a new release of android-validation-komensky with gradle?

    Cheers.

    opened by Narayane 0
  • FormValidator.validate(Activity activity, IValidationCallback callback) - Not shown error for all the failed fields

    FormValidator.validate(Activity activity, IValidationCallback callback) - Not shown error for all the failed fields

    Issue 2 : FormValidator.validate(Activity activity, IValidationCallback callback) validate all the fields but show validation fail message for only the first field ( or one field). I expect it should show error on all the failed fields.

    opened by joomsite 0
Releases(0.9.4)
Owner
Inmite s.r.o.
Inmite s.r.o.
High level parsing to ensure your input is in the right shape and satisfies all constraints that business logic requires.

Parsix High level parsing to ensure your input is in the right shape and satisfies all constraints that business logic requires. It is highly inspired

null 188 May 29, 2022
Native solution for common React Native problem of focused views being covered by soft input view.

react-native-avoid-softinput Native solution for common React Native problem of focused views being covered by soft input view. It is solved by listen

Mateusz Mędrek 240 Oct 2, 2022
Validator - Notify type based validation for input fields.

Validator - Notify type based validation for input fields.

Mustafa Yiğit 56 Sep 14, 2022
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 3 Sep 29, 2022
Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Mauricio Togneri 13 Aug 29, 2022
Simple-Claim-Form - Android App for creating a simple dynamic form with MVVM architecture

Simple-Claim-Form Android App for creating a simple dynamic form with MVVM archi

Shubham Gangpuri 1 Aug 14, 2022
Format numbers using a string pattern with this simple number formatted like ##-####-##

AndroidPattern Format numbers using a string pattern with this simple number formatted like ##-####-## Installation To get a Git project into your bui

Hussein Habibi Juybari 2 Oct 25, 2021
A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

MarvinLabs 421 Sep 5, 2022
A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

Wesley Lin 135 Aug 25, 2021
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Jun 19, 2022
A helper library to ease the most repetitive codes with simple reusable attributes.

ak-universal-android-helper A helper library to ease the most repetitive codes with simple reusable attributes. AKUAH can help you with many repetitiv

Aakash Kumar 20 Jul 8, 2020
A Simple Android Library for Kenyan Counties

A Simple Android Library for Kenyan Counties

Joel Kanyi 18 Jul 12, 2022
nestegg - Very simple Kotlin caching library

nestegg - Very simple Kotlin caching library

Runner-be 4 Jun 15, 2022
Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 669 Jul 30, 2022
A lightweight library for config and using SharedPreferences

preferences-helper SharePreferences is very popular with any project and all most all project has SharePreferences for saving data. This library will

Khang Tran 23 May 8, 2021
a simple cache for android and java

ASimpleCache ASimpleCache 是一个为android制定的 轻量级的 开源缓存框架。轻量到只有一个java文件(由十几个类精简而来)。 1、它可以缓存什么东西? 普通的字符串、JsonObject、JsonArray、Bitmap、Drawable、序列化的java对象,和 b

Michael Yang 3.7k Sep 29, 2022
✔️ Secure, simple key-value storage for Android

Hawk 2.0 Secure, simple key-value storage for android Important Note This version has no backward compatibility with Hawk 1+ versions. If you still wa

Orhan Obut 3.9k Sep 27, 2022
Create a simple and more understandable Android logs.

DebugLog Create a simple and more understandable Android logs. #Why? android.util.Log is the most usable library of the Android. But, when the app rel

mf 419 Sep 19, 2022
Ask Permission - Simple RunTime permission manager

Ask Permission https://kishanjvaghela.github.io/Ask-Permission/ Simple RunTime permission manager How to use Add url to your gradle file compile 'com.

Kishan Vaghela 78 Sep 19, 2022