https://github.com/radoyankov/valigator
Validation tools for EditText fields
https://github.com/radoyankov/valigator
Last synced: 22 days ago
JSON representation
Validation tools for EditText fields
- Host: GitHub
- URL: https://github.com/radoyankov/valigator
- Owner: radoyankov
- License: mit
- Created: 2018-12-15T10:01:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-18T09:30:04.000Z (over 6 years ago)
- Last Synced: 2024-08-01T19:56:55.990Z (9 months ago)
- Language: Kotlin
- Size: 274 KB
- Stars: 69
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - radoyankov/valigator - Validation tools for EditText fields (Kotlin)
README

Validate EditText fields in a couple of lines, with custom, scalable validations.
[](https://bintray.com/radoslav/maven/valigator) [](http://twitter.com/Radoslav_Y)
## Usage
Valigator enables you to easily validate EditTexts with custom validations.
Here's how you do that!First you create your validators.
The library supports 2 types of validators. One which doesn't have any external dependencies, and one which does. You can use the second type if your validation is dependant on external data.```kotlin
val normalValidator = Validator("Optional Error Message") {
text.length < 5
}val customValidator = Validator.Custom("Custom Error Message") { button : RadioButton ->
button?.isChecked == true && text.contains("spaceX")
}
//Multiple errors in one validation
val multipleErrorValidator = Validator{
//it's a good idea to return true inside the checks, to tell the library you've already handled the error
if (this == null) {
error = "Null object"
true
} else if (text.isEmpty()) {
error = "Text is empty"
true
} else false
}
```The second kind of validation requires a class type to be specified. This is the type of the external data it will be expecting.
The second step is to enable the validator on EditText fields.
```kotlin
edit_text.setValidator(normalValidator)edit_text_1.setValidator(normalValidator)
edit_text_2.setValidator(customValidator.addDependency(button_dependency))
edit_text_3.setValidator("Simple validation") {
text.isNotEmpty()
}
```**Important**: For external dependancy validations it's required to add a dependency with the `addDependency()` function. Only one dependency is supported, but it can be anything, for example, a list of views.
You can see the third EditText field which accepts a String and a function. That one is a third, extra kind of validation, which doesn't require any premade validators, and can validate fields on the go.
That's it! When you set up the validators, each time the text inside of the EditText field changes, the validation will be preformed.
Here's a preview of those fields:

---
## Download### Manually
You can manually download [the library class](https://github.com/RadoslavYankov/valigator/blob/master/valigator/src/main/java/com/radoslav/valigator/Validator.kt) and use it in your application.
### Gradle
```gradle
dependencies {
implementation 'com.radoslav.valigator:valigator:$latest_version'}
```
### Maven
```xmlcom.radoslav.valigator
valigator
latest_version
pom```
---
## CompatibilityMinimum Android SDK: API level 19
---
## AuthorRadoslav Yankov [@Radoslav_Y](https://twitter.com/Radoslav_Y)
---
## Getting helpIf you spot a problem you can open an issue on the Github page, or alternatively, you can tweet me at [@Radoslav_Y](https://twitter.com/Radoslav_Y)
---
## LicenseFastList is released under the [MIT License](https://github.com/RadoslavYankov/valigator/blob/master/LICENSE).