Code Monkey home page Code Monkey logo

z-validations's Introduction

z-validations

Small library that helps with Android form validations

Library was written in scope of post: Android form validation - the right way

Chuck Noris is always valid

Available validations

  • NotEmpty - checks if field is not blank
  • IsEmail - checks if field is valid email
  • IsPositiveInteger - checks if fiels value is integer and if value > 0
  • InRange - checks if field value is integer and is in range min < value < max
  • HasMinimumLength - checks if field value lenght is value.lenght >= min

You can easily create your own validations, just implement ua.org.zasadnyy.zvalidations.validation.Validation interface

Sample usage

Include into your project. If you're using gradle simply copy z-validations-library folder into your project and update your build.gradle dependencies list

    dependencies {
        compile project(':z-validations-library')
        ...
    }

Create validation form and add some validations

    Form mForm = new Form(mActivity);
    mForm.addField(Field.using(mNameEditText).validate(NotEmpty.build(mContext)));
    mForm.addField(Field.using(mEmailEditText).validate(NotEmpty.build(mContext)).validate(IsEmail.build(mContext)));
    mForm.addField(Field.using(mAgeEditText).validate(InRange.build(mContext, 0, 120)));

Check if form is valid

    private void submit() {
        if (mForm.isValid()) {
            Toast.makeText(this, "Form is valid", Toast.LENGTH_SHORT).show();
        }
    }

Since v.0.2 you can change how validation errors are displayed. Library includes error renderers using TextView errors (used by default) and Toasts. You can create your own by implementing ua.org.zasadnyy.zvalidations.ValidationFailedRenderer interface

    mForm.setValidationFailedRenderer(new TextViewValidationFailedRenderer(mContext));

Checkout sample project for full usage example or install it from Google Play

Changelog

Current version: 0.2

v.0.2.1

  • Added HasMinimumLength validation (thanks TheoTzaferis for pull request)

v.0.2

v.0.1

  • Initial release

Bitdeli Badge

z-validations's People

Contributors

zasadnyy avatar bitdeli-chef avatar

Watchers

James Cloos avatar macca 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.