From f79ea8fa4b882fd02bb52d4bcbd26f8ab1011729 Mon Sep 17 00:00:00 2001 From: Gurleen Sethi Date: Mon, 11 Sep 2017 10:58:17 +0530 Subject: [PATCH 1/4] Update README.md --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60973f6..323eb19 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ allprojects { ``` 2. Add the `LiteUtilities` dependency in your app level `build.gradle` file ```gradle -compile 'com.github.gurleensethi:LiteUtilities:v1.1.0' +compile 'com.github.gurleensethi:LiteUtilities:v1.2.0' ``` #### Current Features @@ -24,6 +24,7 @@ compile 'com.github.gurleensethi:LiteUtilities:v1.1.0' * [ScrollUtils](#scrollutils) - Easily hide/show FloationActionButton on scroll when using RecyclerView or NestedScrollView. * [ToastUtils](#toastutils) - Creating toasts are just a function away. * [SPUtils](#sputils) - Simple DSL for Shared Preferences. +* [ValidatorUtils](#validatorutils) - Fast and simple text validation. #### Motivation Primary motivation behind the development of this library is to hide the day-to-day boilerplate code that android developers have to deal with, by providing a simple and concise API, but also maintaining complete functionality at the same time. @@ -201,6 +202,71 @@ getFromSharedPreferences("SP", "string", "default") getFromSharedPreferences("SP", "string", "default") ``` +ValidatorUtils +====== + +Set of functions that provide easy and fast text validation. More than 15+ validation types available. +Use the `Validator` class to access all the validation functions. This class is available using an extension function on `EditText` and `TextInputEditText`. Just call the `validator()` function. + +Using `Validator` directly on `EditText`. +```kotlin +var result: Boolean = editText.validator() + .email() + .atLeastOneUpperCase() + .atLeastOneLowerCase() + .maximumLength(20) + .minimumLength(5) + .noNumbers() + .validate() +``` +The `Validator` class has all the validation functions, chain all the functions that you require and call `validate()` to process. The result returend is a `Boolean`, `true` if all validation are passed, `false` if any one of them fails. + +### Adding callbacks to listen to results +If you want to take action after the validation is complete, there are two callbacks available, `addSuccessCallback()` and `addErrorCallback(ValidationError)`. The `addSuccessCallback` is invoked when the valdiation passes, `addErrorCallback` is invoked when validation fails. + +```kotlin +var result = editText.validator() + .email() + .atLeastOneUpperCase() + .atLeastOneLowerCase() + .maximumLength(20) + .minimumLength(5) + .noNumbers() + .addSuccessCallback { + //Proceed + } + .addErrorCallback { errorType -> + when (errorType) { + ValidationError.EMAIL -> { + editText.error = "Email format is incorrect" + } + ValidationError.AT_LEAST_ONE_LOWER_CASE -> { + editText.error = "Please provide at-least one lower case letter" + } + ValidationError.AT_LEAST_ONE_UPPER_CASE -> { + editText.error = "Please provide at-least one upper case letter" + } + else -> { + editText.error = "Not Enough" + } + } + } + .validate() +``` +The `addErrorCallback` also provides a parameter of type `ValidationError`. This parameter provies the type of validation error that has occured. `ValidationError` is an enum, the naming convention is very simple, the names are same as the corresponding validation functions. For example, for validation function `atLeastOneLowerCase`, the validation error will be `ValidationError.AT_LEAST_ONE_LOWER_CASE`. + +### Using Validator independently +`Validator` class can also be used independently, just instantiate an object of it. +```kotlin +val validator = Validator("somePassword#123") +validator.atLeastOneNumber() + .atLeastOneUpperCase() + .minimumLength(8) + .maximumLength(32) + .atLeastOneSpecialCharacter() + .validate() +``` + Support ====== From ad781f92bd21271f9303112b40649eee724f97e6 Mon Sep 17 00:00:00 2001 From: Gurleen Sethi Date: Mon, 11 Sep 2017 11:03:42 +0530 Subject: [PATCH 2/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 323eb19..10392d0 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,7 @@ var result: Boolean = editText.validator() .noNumbers() .validate() ``` -The `Validator` class has all the validation functions, chain all the functions that you require and call `validate()` to process. The result returend is a `Boolean`, `true` if all validation are passed, `false` if any one of them fails. +The `Validator` class has all the validation functions, chain all the functions that you require and call `validate()` to process. The result returned is a `Boolean`, `true` if all validation are passed, `false` if any one of them fails. ### Adding callbacks to listen to results If you want to take action after the validation is complete, there are two callbacks available, `addSuccessCallback()` and `addErrorCallback(ValidationError)`. The `addSuccessCallback` is invoked when the valdiation passes, `addErrorCallback` is invoked when validation fails. From 81959327c62a8932362359b0ed4d0fb77c092a30 Mon Sep 17 00:00:00 2001 From: Gurleen Sethi Date: Tue, 12 Sep 2017 11:39:07 +0530 Subject: [PATCH 3/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 10392d0..211fe9b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ compile 'com.github.gurleensethi:LiteUtilities:v1.2.0' * [SPUtils](#sputils) - Simple DSL for Shared Preferences. * [ValidatorUtils](#validatorutils) - Fast and simple text validation. +##### The library is designed in such a way that if don't want to import the complete library but only want a specific Util, then you can download the corresponding file for the required Util, every Util has its own file/files and is not dependent on any other Util + #### Motivation Primary motivation behind the development of this library is to hide the day-to-day boilerplate code that android developers have to deal with, by providing a simple and concise API, but also maintaining complete functionality at the same time. From 4e535639b3889e6112233942e87c2760377aeb39 Mon Sep 17 00:00:00 2001 From: Gurleen Sethi Date: Tue, 12 Sep 2017 11:40:27 +0530 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 211fe9b..0b14d0b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ compile 'com.github.gurleensethi:LiteUtilities:v1.2.0' * [SPUtils](#sputils) - Simple DSL for Shared Preferences. * [ValidatorUtils](#validatorutils) - Fast and simple text validation. -##### The library is designed in such a way that if don't want to import the complete library but only want a specific Util, then you can download the corresponding file for the required Util, every Util has its own file/files and is not dependent on any other Util +##### The library is designed in such a way that if don't want to import the complete library but only want a specific Util, then you can download the corresponding file for the required Util, every Util has its own file/files and is not dependent on any other Util. You can find the code [here](https://github.com/gurleensethi/LiteUtilities/tree/master/liteutils/src/main/java/com/thetechnocafe/gurleensethi/liteutils). #### Motivation Primary motivation behind the development of this library is to hide the day-to-day boilerplate code that android developers have to deal with, by providing a simple and concise API, but also maintaining complete functionality at the same time.