Skip to content

Simple, flexible, and highly extensible form validations

License

Notifications You must be signed in to change notification settings

tentenponce/FlexValidation

Repository files navigation

FlexValidation

codecov Build Status Download

Simple, flexible, and highly extensible form validations.

Why use this?

  • Can be easily plugged into your project no matter what architecture you are using.
  • Highly extensible, create your own validations!
  • Just exactly what you need, pure validation classes only.
  • Less than 30KB!!!
  • Complete documentation and tests.

How to use

Add this on the dependencies block of your app level build.gradle.

android {
  ...
}

dependencies {
  ...
  implementation "com.tcorner:flexvalidation:<latest version here>"
}

Simply use the validation you want:

Kotlin

AlphabetValidation().isValid("abc") // returns true
AlphabetValidation().isValid("abc123") // returns false

Java

new AlphabetValidation().isValid("abc"); // returns true
new AlphabetValidation().isValid("abc123"); // returns false

Create your own validation!

Kotlin

class YourValidation: Validation() {
  override fun isValid(o: Any): Boolean {
    // your logic here, check first for data type of parameter o
  }
}

Java

public class YourValidation extends Validation {
  @Override
  public boolean isValid(Object o) {
    // your logic here, check first for data type of parameter o 
  }
}

You can also combine multiple validations:

Kotlin

Validator.validate(
  "password123",
  arrayOf(
    RequiredValidation(),
    MinMaxValidation(8, 16),
    SpecialCharacterValidation(),
    LowerCaseValidation(),
    UpperCaseValidation(),
    NumberValidation()
  )
) // returns the first validation object that fails

Java

Validator.INSTANCE.validate(
  "password123",
  new Validation[]{
    new RequiredValidation(),
    new MinMaxValidation(8, 16),
    new SpecialCharacterValidation(),
    new LowerCaseValidation(),
    new UpperCaseValidation(),
   new NumberValidation()
  }
); // returns the first validation object that fails

Author

Exequiel Egbert V. Ponce, poncetenten10@gmail.com

Releases

No releases published

Packages

No packages published

Languages