All Projects → thyrlian → Awesomevalidation

thyrlian / Awesomevalidation

Licence: mit
Android validation library which helps developer boil down the tedious work to three easy steps.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Awesomevalidation

Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+78.13%)
Mutual labels:  validation, form, forms, input
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+520.4%)
Mutual labels:  validation, form, forms
Formik Alicante
Formik slides & demos from React Alicante
Stars: ✭ 47 (-95.7%)
Mutual labels:  validation, form, forms
Customui
Library to create custom UI's in MCPE 1.2+
Stars: ✭ 60 (-94.51%)
Mutual labels:  form, forms, input
Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-96.34%)
Mutual labels:  validation, form, forms
Validation
Framework agnostic validation library for PHP
Stars: ✭ 146 (-86.64%)
Mutual labels:  validation, forms, input
React Native Merlin
🧙 Simple web-like forms in react native.
Stars: ✭ 83 (-92.41%)
Mutual labels:  validation, form, forms
Redux Form
A Higher Order Component using react-redux to keep form state in a Redux store
Stars: ✭ 12,597 (+1052.52%)
Mutual labels:  validation, form, forms
React Hook Form
📋 React Hooks for form state management and validation (Web + React Native)
Stars: ✭ 24,831 (+2171.82%)
Mutual labels:  validation, form, forms
Form Backend Validation
An easy way to validate forms using back end logic
Stars: ✭ 784 (-28.27%)
Mutual labels:  validation, form
Winterfell
Generate complex, validated and extendable JSON-based forms in React.
Stars: ✭ 787 (-28%)
Mutual labels:  validation, forms
Insert Text At Cursor
Fast crossbrowser insertion of text at cursor position in a textarea / input
Stars: ✭ 49 (-95.52%)
Mutual labels:  form, input
Hyperform
Capture form validation back from the browser
Stars: ✭ 729 (-33.3%)
Mutual labels:  validation, input
Formsy React
A form input builder and validator for React JS
Stars: ✭ 708 (-35.22%)
Mutual labels:  validation, form
Formik
Build forms in React, without the tears 😭
Stars: ✭ 29,047 (+2557.55%)
Mutual labels:  form, forms
Form Js
Easily create web forms. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.
Stars: ✭ 9 (-99.18%)
Mutual labels:  forms, input
Verticalstepperform
Vertical Stepper Form Library for Android. It follows Google Material Design guidelines.
Stars: ✭ 868 (-20.59%)
Mutual labels:  form, forms
Form2js
Javascript library for collecting form data
Stars: ✭ 630 (-42.36%)
Mutual labels:  form, forms
Swiftyform
iOS framework for creating forms
Stars: ✭ 907 (-17.02%)
Mutual labels:  validation, form
Ok
✔️ A tiny TypeScript library for form validation
Stars: ✭ 34 (-96.89%)
Mutual labels:  validation, form

API JCenter JitPack Build & Test Travis CI Status CircleCI Status Codacy Badge Android Arsenal Android Weekly Trusted By Many Apps AppBrain

AwesomeValidation

Introduction

Implement validation for Android within only 3 steps. Developers should focus on their awesome code, and let the library do the boilerplate. And what's more, this could help keep your layout file clean.

Steps

  1. Declare validation style;
  2. Add validations;
  3. Set a point when to trigger validation.

Sample code

// Step 1: designate a style
AwesomeValidation mAwesomeValidation = new AwesomeValidation(BASIC);
// or
AwesomeValidation mAwesomeValidation = new AwesomeValidation(COLORATION);
mAwesomeValidation.setColor(Color.YELLOW);  // optional, default color is RED if not set
// or
AwesomeValidation mAwesomeValidation = new AwesomeValidation(UNDERLABEL);
mAwesomeValidation.setContext(this);  // mandatory for UNDERLABEL style
// setUnderlabelColor is optional for UNDERLABEL style, by default it's holo_red_light
mAwesomeValidation.setUnderlabelColorByResource(android.R.color.holo_orange_light); // optional for UNDERLABEL style
mAwesomeValidation.setUnderlabelColor(ContextCompat.getColor(this, android.R.color.holo_orange_dark)); // optional for UNDERLABEL style
// or
AwesomeValidation mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
mAwesomeValidation.setTextInputLayoutErrorTextAppearance(R.style.TextInputLayoutErrorStyle); // optional, default color is holo_red_light if not set
// by default, it automatically sets focus to the first failed input field after validation is triggered
// you can disable this behavior by
AwesomeValidation.disableAutoFocusOnFirstFailure();

// Step 2: add validations
// support regex string, java.util.regex.Pattern and Guava#Range
// you can pass resource or string
mAwesomeValidation.addValidation(activity, R.id.edt_name, "[a-zA-Z\\s]+", R.string.err_name);
mAwesomeValidation.addValidation(activity, R.id.edt_tel, RegexTemplate.TELEPHONE, R.string.err_tel);
mAwesomeValidation.addValidation(activity, R.id.edt_email, android.util.Patterns.EMAIL_ADDRESS, R.string.err_email);
mAwesomeValidation.addValidation(activity, R.id.edt_year, Range.closed(1900, Calendar.getInstance().get(Calendar.YEAR)), R.string.err_year);
mAwesomeValidation.addValidation(activity, R.id.edt_height, Range.closed(0.0f, 2.72f), R.string.err_height);
// or
mAwesomeValidation.addValidation(editText, "regex", "Error info");

// to validate TextInputLayout, pass the TextInputLayout, not the embedded EditText
AwesomeValidation mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
mAwesomeValidation.addValidation(activity, R.id.til_email, Patterns.EMAIL_ADDRESS, R.string.err_email);

// to validate the confirmation of another field
String regexPassword = "(?=.*[a-z])(?=.*[A-Z])(?=.*[\\d])(?=.*[~`;
mAwesomeValidation.addValidation(activity, R.id.edt_password, regexPassword, R.string.err_password);
// to validate a confirmation field (don't validate any rule other than confirmation on confirmation field)
mAwesomeValidation.addValidation(activity, R.id.edt_password_confirmation, R.id.edt_password, R.string.err_password_confirmation);

// to validate with a simple custom validator function
mAwesomeValidation.addValidation(activity, R.id.edt_birthday, new SimpleCustomValidation() {
    @Override
    public boolean compare(String input) {
        // check if the age is >= 18
        try {
            Calendar calendarBirthday = Calendar.getInstance();
            Calendar calendarToday = Calendar.getInstance();
            calendarBirthday.setTime(new SimpleDateFormat("dd/MM/yyyy", Locale.US).parse(input));
            int yearOfToday = calendarToday.get(Calendar.YEAR);
            int yearOfBirthday = calendarBirthday.get(Calendar.YEAR);
            if (yearOfToday - yearOfBirthday > 18) {
                return true;
            } else if (yearOfToday - yearOfBirthday == 18) {
                int monthOfToday = calendarToday.get(Calendar.MONTH);
                int monthOfBirthday = calendarBirthday.get(Calendar.MONTH);
                if (monthOfToday > monthOfBirthday) {
                    return true;
                } else if (monthOfToday == monthOfBirthday) {
                    if (calendarToday.get(Calendar.DAY_OF_MONTH) >= calendarBirthday.get(Calendar.DAY_OF_MONTH)) {
                        return true;
                    }
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    }
}, R.string.err_birth);

// to validate with your own custom validator function, warn and clear the warning with your way
mAwesomeValidation.addValidation(activity, R.id.spinner_tech_stacks, new CustomValidation() {
    @Override
    public boolean compare(ValidationHolder validationHolder) {
        if (((Spinner) validationHolder.getView()).getSelectedItem().toString().equals("< Please select one >")) {
            return false;
        } else {
            return true;
        }
    }
}, new CustomValidationCallback() {
    @Override
    public void execute(ValidationHolder validationHolder) {
        TextView textViewError = (TextView) ((Spinner) validationHolder.getView()).getSelectedView();
        textViewError.setError(validationHolder.getErrMsg());
        textViewError.setTextColor(Color.RED);
    }
}, new CustomErrorReset() {
    @Override
    public void reset(ValidationHolder validationHolder) {
        TextView textViewError = (TextView) ((Spinner) validationHolder.getView()).getSelectedView();
        textViewError.setError(null);
        textViewError.setTextColor(Color.BLACK);
    }
}, R.string.err_tech_stacks);

// Step 3: set a trigger
findViewById(R.id.btn_done).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mAwesomeValidation.validate();
    }
});

// Optional: remove validation failure information
findViewById(R.id.btn_clr).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mAwesomeValidation.clear();
    }
});

Attention

  • It works perfectly with Fragment, but please pay attention to Fragment's lifecycle. You should set the validate() inside Fragment's onActivityCreated instead of onCreateView or any other early stage.

  • UNDERLABEL validation style doesn't support ConstraintLayout at the moment, please use other validation styles. There is an open issue here.

Import as dependency

For Gradle it's easy - just add below to your module's build.gradle (it's available on JCenter):

dependencies {
    implementation 'com.basgeekball:awesome-validation:4.2'
}

Alternatively, it's also available on JitPack:

  • Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the dependency
dependencies {
    implementation 'com.github.thyrlian:AwesomeValidation:v4.2'
    // you can also use the short commit hash to get a specific version
    // implementation 'com.github.thyrlian:AwesomeValidation:GIT_COMMIT_HASH'
}

Screenshots

Release guide

  • Update version number in build.gradle, gradle.properties and README
  • Create new git tag: v*.*
  • Run ./gradlew clean build && ./gradlew generateRelease to generate release zip file
  • Run ./gradlew bintrayUpload to create a new version in bintray (first make sure that environment variables BINTRAY_USER & BINTRAY_KEY are set)
  • Upload release zip file manually to bintray, make sure to check 'Explode this archive'

Stargazers over time

Stargazers over time

License

Copyright (c) 2014-2021 Jing Li. See the LICENSE file for license rights and limitations (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].