Skip to content

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

License

Notifications You must be signed in to change notification settings

stephanenicolas/AwesomeValidation

 
 

Repository files navigation

API JCenter Build Status Codacy Badge Android Arsenal Android Weekly Stories in Ready

#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

// 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");

// 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();
    }
});

##Import as dependency For Gradle it's so easy: just add below compile line to your module's build.gradle (it's available on JCenter).

dependencies {
    compile 'com.basgeekball:awesome-validation:1.2'
}

##Screenshots

##Release guide

  • Update version number in build.gradle, gradle.properties and README
  • Run gradle clean build generateRelease to generate release zip file
  • Run gradle bintrayUpload to create a new version in bintray
  • Upload release zip file manually to bintray, make sure to check 'Explode this archive'

##License Copyright (c) 2015 Jing Li. See the LICENSE file for license rights and limitations (MIT).

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%