RxValidator
phajduk
61
Visit GitHub RepoValidation

RxValidator

Build Status

Easy Android form validation in Rx way.

Dependencies

  • RxJava
  • RxBinding

Usage

RxValidator provides fluent API to define validation rules:

Observable<RxValidationResult> observable = 
    RxValidator.createFor(password)
        .nonEmpty()
        .length("Min length is 5", 5)
        .onFocusChanged()
        .toObservable();

In above example nonEmpty and length are validators, .onFocusChanged() decides about validation trigger.

Validators

At the moment we have following pre-defined validation rules:

  • email
  • nonEmpty
  • digitOnly
  • length
  • minLength
  • maxLength
  • age
  • sameAs
  • ip4

You can also provide custom validation rule using with(Validator<EditText> externalValidator) operator. It gives you possibility to define your own rules e.g. validate e-mail via HTTP call.

Validation trigger

In order to decide, when validation should be launched you can choose one from the following options:

  • onFocusChanged - validation result is emitted when EditText lost focus
  • onValueChanged - validation result is emitted when value of EditText changed
  • onSubscribe - validation result is emitted immediately

Download

Gradle:

repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.phajduk:RxValidator:94fdca4ec6504985d6187080f1d9e9580703c082' //commit hash
}

License

Copyright 2016 Pawel Hajduk

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.
Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT