-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
explain how to create a custom validable
- Loading branch information
1 parent
5f377a8
commit 05b8a16
Showing
4 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Create a validable | ||
|
||
You can create a validable with a custom validation logic. | ||
|
||
All you need to do is to extend the `BaseValidable` class, which takes two functions as parameters: | ||
|
||
- `validator`: This function checks if the value meets a specified condition and returns a boolean. | ||
- `errorFor`: Is called when the value does not meet the condition and returns a string as the error message. | ||
|
||
Let's see an example of a custom validable that checks if an input contains the word "devscast" | ||
|
||
```kotlin | ||
class DevscastValidable : BaseValidable( | ||
validator = { value -> | ||
value.contains("devscast", ignoreCase = true) | ||
}, | ||
errorFor = { value -> | ||
"$value does not contain the word 'devscast'." | ||
} | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters