Skip to content

JSR-303 compatibile validator that allows to create JavaScript based validation rules with the same logic for backend and frontend

Notifications You must be signed in to change notification settings

tomek39856/isomorphic-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Isomorphic Validator

JSR-303 compatibile validator that allows to create JavaScript based validation rules with the same logic for backend and frontend.

Usage examples

Creating simple validator

Create js validation file and put in resource directory. File should contain methods returning true or false and one parameter for value of field to be tested. Create js files with validation logic

testValidator.js

function validateLengthMin(test) {
     if(test == null) {
        return true;
     }
     return test.length>5;
}

function validateLengthMax(test) {
     if(test == null) {
        return true;
     }
     return test.length<10;
}

Annotate your entity properties with @IsomorphicConstraint:

@IsomorphicConstraint(jsFilePath = "testValidator.js", jsMethods = {"validateLengthMin", "validateLengthMax"})
private String fieldToTest;

It's also possible to use multiple @IsomorphicConstraint annotations on single field. For examples please check project unit tests.

Prerequisites

Java 1.8 or higher
Gradle
Any JSR-303 validation implemmentation (for instance Hibernate Validator)

Built With

  • [Gradle] - Dependency Management

Author

About

JSR-303 compatibile validator that allows to create JavaScript based validation rules with the same logic for backend and frontend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published