All Projects → deva666 → KValidation

deva666 / KValidation

Licence: other
Validation library. Fluent syntax in Java, mini DSL in Kotlin

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to KValidation

valite
🔥 Concurrently execute your validators in a simple, practical and light validator engine.
Stars: ✭ 20 (+0%)
Mutual labels:  validator
codeowners-validator
The GitHub CODEOWNERS file validator
Stars: ✭ 142 (+610%)
Mutual labels:  validator
max-validator
Advanced validation library for Javascript & React | Inspired by laravel validation
Stars: ✭ 29 (+45%)
Mutual labels:  validator
national-code
Simple implementation of Iranian national code validation
Stars: ✭ 31 (+55%)
Mutual labels:  validator
ZUV
ZUgferd validator using Verapdf
Stars: ✭ 22 (+10%)
Mutual labels:  validator
Natours
An awesome tour booking web app written in NodeJS, Express, MongoDB 🗽
Stars: ✭ 94 (+370%)
Mutual labels:  validator
hey-validator
Data validator
Stars: ✭ 14 (-30%)
Mutual labels:  validator
jisp
Small Lisp expression interpreter made in Java
Stars: ✭ 19 (-5%)
Mutual labels:  jvm-languages
volder
volder is powerful Object schema validation lets you describe your data using a simple and readable schema and transform a value to match the requirements
Stars: ✭ 106 (+430%)
Mutual labels:  validator
toi
A TypeScript validation library capable of inferring types
Stars: ✭ 25 (+25%)
Mutual labels:  validator
utf8-validator
UTF-8 Validator
Stars: ✭ 18 (-10%)
Mutual labels:  validator
python-sshpubkeys
OpenSSH public key parser for Python
Stars: ✭ 85 (+325%)
Mutual labels:  validator
vayder
Easy and concise validations for Express routes
Stars: ✭ 26 (+30%)
Mutual labels:  validator
simple-validator
Simple Validator is an awesome and easy to use validator for php
Stars: ✭ 73 (+265%)
Mutual labels:  validator
romans
A Simple PHP Roman Numerals Library
Stars: ✭ 40 (+100%)
Mutual labels:  validator
Hammer
Simple, reliable FHIR validator
Stars: ✭ 27 (+35%)
Mutual labels:  validator
formurai
Lightweight and powerfull library for declarative form validation
Stars: ✭ 49 (+145%)
Mutual labels:  validator
typepy
A Python library for variable type checker/validator/converter at a run time.
Stars: ✭ 16 (-20%)
Mutual labels:  validator
validator
Yii validator library
Stars: ✭ 47 (+135%)
Mutual labels:  validator
swagger-object-validator
Node-Module to validate your model against a swagger spec and receive in-depth error traces
Stars: ✭ 27 (+35%)
Mutual labels:  validator

Build Status License

KValidation

Validation library for Kotlin/Java


Example:

Create the validator class by extending the generic ValidatorBase<T> class.

class UserValidator extends ValidatorBase<User> {
}

Java

User user = new User();
UserValidator validator = new UserValidator(user);

validator.forProperty(User::getName)
             .length(4)
             .mustBe(n -> n.startsWith("J"))
             .notEqual("John")
             .onError()
             .errorMessage("Name should start with J, be 4 characters in length and not be John");

ValidationResult result = validator.validate();

if (result.isValid()) {
  // woohooo
} else {
  for(ValidationError err : result.getValidationErrors()) {
    System.out.print(err.toString());
  }
}

Kotlin has even nicer syntax

val user = User()
val validator = UserValidator(user)
    
validator.forProperty { p -> p.name } rules {
    length(4)
    mustBe { n -> n.startsWith("J") }
    notEqual("John")
} onError {
    errorMessage("Name should start with J, be 4 characters in length and not be John")
}
    
val result = validator.validate()

If you don't want to create a validator class, add InnerValidator inside the validated class

class User(private val name: String, private val age: Int) {
    val validator = InnerValidator(this) setRules {
        forProperty { p -> p.name } rules {
            equal("John")
        }
    }
 }

Contributing

Contributions are always welcome, just fork the project and submit a pull request.


Written by Marko Devcic

License APL 2.0

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].