https://github.com/notninja/verifier
Java library for validation
https://github.com/notninja/verifier
java validation verification
Last synced: 5 months ago
JSON representation
Java library for validation
- Host: GitHub
- URL: https://github.com/notninja/verifier
- Owner: NotNinja
- License: mit
- Created: 2016-10-11T14:04:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T09:37:09.000Z (over 8 years ago)
- Last Synced: 2025-01-11T06:28:39.715Z (over 1 year ago)
- Topics: java, validation, verification
- Language: Java
- Size: 787 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Verifier
[Verifier](https://github.com/NotNinja/verifier) is a Java library for validation which concentrates on providing a
simple API with useful (and readable!) error messages, all while being highly configurable so that it's useful in your
application code.
[](https://travis-ci.org/NotNinja/verifier)
[](https://codecov.io/gh/NotNinja/verifier)
[](https://crowdin.com/project/verifier)
[](https://www.javadoc.io/doc/org.notninja/verifier)
[](https://github.com/NotNinja/verifier/blob/master/LICENSE.md)
[](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.notninja%22%20AND%20a%3A%22verifier%22)
* [Install](#install)
* [API](#api)
* [Bugs](#bugs)
* [Contributors](#contributors)
* [License](#license)
## Install
To install Verifier, simply add it as a dependency to your project:
**Maven:**
``` xml
org.notninja
verifier
0.3.0
```
**Gradle:**
``` groovy
compile 'org.notninja:verifier:0.3.0'
```
That's it! You'll need to have Java 8 or above though.
## API
Verifier offers validation methods for a lot of standard Java data types:
``` java
package com.example.form;
import org.notninja.verifier.Verifier;
public class LoginForm implements Form {
UserService userService;
@Override
public void handle(Map data) {
Verifier.verify(data)
.containAllKeys("username", "password");
.and(data.get("username"), "username")
.not().blank();
.and(data.get("password"), "password")
.not().empty()
.alphanumeric();
userService.login(data);
}
}
```
However, you can also provide implementations of `CustomVerifier` to support more specific use cases instead of just
data types.
``` java
package com.example.form;
import com.example.verifier.PasswordVerifier;
import org.notninja.verifier.Verifier;
public class RegistrationForm implements Form {
UserService userService;
@Override
public void handle(Map data) {
Verifier.verify(data)
.containAllKeys("username", "password");
.and(data.get("username"), "username")
.not().blank()
.that((value) -> userService.isAvailable(value));
.and(data.get("password"), "password", PasswordVerifier.class)
.not().nulled()
.strong();
userService.register(data);
}
}
```
The best way to learn about the API is to simply use it and explore. It's designed to be very natural and simple. Each
verification method is documented with examples to help explain exactly what's being verified.
Here's a list of the data types supported by Verifier already:
* Array
* BigDecimal
* BigInteger
* Boolean
* Byte
* Calendar
* Character
* Class
* Collection
* Comparable
* Date
* Double
* Float
* Integer
* Locale
* Long
* Map
* Object
* Short
* String
* Throwable
If a data type is missing that you'd like to see supported by Verifier, please take a look at the
[Contributors](#contributors) section below.
## Bugs
If you have any problems with Verifier or would like to see changes currently in development you can do so
[here](https://github.com/NotNinja/verifier/issues).
## Contributors
If you want to contribute, you're a legend! Information on how you can do so can be found in
[CONTRIBUTING.md](https://github.com/NotNinja/verifier/blob/master/CONTRIBUTING.md). We want your suggestions and pull
requests!
A list of Verifier contributors can be found in[AUTHORS.md](https://github.com/NotNinja/verifier/blob/master/AUTHORS.md).
## License
See [LICENSE.md](https://github.com/NotNinja/verifier/raw/master/LICENSE.md) for more information on our MIT license.
[](https://not.ninja)