Validator - Notify type based validation for input fields.

Overview

Validator

License Medium

Validate your inputs by notify types

Import

  • project level
allprojects {
 repositories {
 // ...
   maven { url 'https://jitpack.io' }
  }
}
  • module level
dependencies {
    implementation 'com.github.mustafayigitt:validator:Tag'
}

How to use

mBinding.txtInputEmail.editText?.doOnTextChanged { text, _, _, _ -> validator.input = text.toString() } mBinding.txtInputEmail.editText?.setOnFocusChangeListener { _, isFocused -> validator.isFocused = isFocused } } .onValidate { isValid, errorMessage, notifyType -> Log.d( "Validator", "notifyType: $notifyType, isValid: $isValid, errorMessage: $errorMessage" ) mBinding.txtInputEmail.error = errorMessage } .build()">
// Create a validator with Builder pattern
val emailValidator = Validator.Builder()
    .addRules(
        ValidatableRule.Email("Enter valid mail address"),
        ValidatableRule.Required("Email is required", NotifyType.ON_FOCUS_CHANGE),
        ValidatableRule.Required("Email is required", NotifyType.ON_FORM_SUBMIT),
        ValidatableRule.Email("Enter valid mail address", NotifyType.ON_FORM_SUBMIT),
    )
    .addCollector { validator ->
        mBinding.txtInputEmail.editText?.doOnTextChanged { text, _, _, _ ->
            validator.input = text.toString()
        }
        mBinding.txtInputEmail.editText?.setOnFocusChangeListener { _, isFocused ->
            validator.isFocused = isFocused
        }
    }
    .onValidate { isValid, errorMessage, notifyType ->
        Log.d(
            "Validator",
            "notifyType: $notifyType, isValid: $isValid, errorMessage: $errorMessage"
        )
        mBinding.txtInputEmail.error = errorMessage
    }
    .build()

Or you can write a custom ValidatableRule

class PasswordConfirmRule(
    override val errorMessage: String,
    override val notifyType: NotifyType,
    val originalInputGetter: () -> String
) : BaseValidatableRule(
    errorMessage = errorMessage,
    notifyType = notifyType,
    rule = { it == originalInputGetter.invoke() }
)

// Usage
val passwordConfirmValidator = Validator.Builder()
    .addRules(
        PasswordConfirmRule(
            errorMessage = "Passwords does not match",
            notifyType = NotifyType.ON_VALUE_CHANGE,
            originalInputGetter = { mBinding.txtInputPassword.editText?.text.toString() },
            )
        )
        ...

License

Copyright 2022 mustafayigitt (Mustafa Yigit)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

compaKTset is a small library aimed at providing you with the most memory efficient Set implementation for any particular data type of your choosing.

compaKTset is a small library aimed at providing you with the most memory efficient Set implementation for any particular data type of your choosing.

Utility library that utilizes KSP to generate Room type converter classes.

Roomie Roomie is an annotation processing library that utilizes KSP to geaRoomie is an annotation processing library that utilizes KSP to generate TypeConverter classes for Room. TypeConverter classes most often involve same boiler-plate code and Roomie makes it really easy to quickly create them with a single annotation.nerate TypeConverter classes for Room. TypeConverter classes most often invol

CreditCardHelper 🖊️  A Jetpack-Compose library providing useful credit card utilities such as card type recognition and TextField ViewTransformations
CreditCardHelper 🖊️ A Jetpack-Compose library providing useful credit card utilities such as card type recognition and TextField ViewTransformations

CreditCardHelper 🖊️ A Jetpack-Compose library providing useful credit card utilities such as card type recognition and TextField ViewTransformations

Native Kotlin library for time-based TOTP and HMAC-based HOTP one-time passwords

A kotlin implementation of HOTP (RFC-4226) and TOTP (RFC-6238). Supports validation and generation of 2-factor authentication codes, recovery codes and randomly secure secrets.

Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as

Multiplaform kotlin library for calculating text differences. Based on java-diff-utils, supports JVM, JS and native targets.

kotlin-multiplatform-diff This is a port of java-diff-utils to kotlin with multiplatform support. All credit for the implementation goes to original a

Releases(1.0.0)
Owner
Mustafa Yiğit
Android Developer
Mustafa Yiğit
Same as the Outlined text fields presented on the Material Design page but with some dynamic changes. 📝 🎉

README SSCustomEditTextOutlineBorder Getting Started SSCustomEditTextOutLineBorder is a small kotlin library for android to support outlined (stroked)

Simform Solutions 194 Dec 30, 2022
UI form validation library for Android

Android Saripaar v2 சரிபார் - sari-paar (Tamil for "to check", "verify" or "validate") Android Saripaar is a simple, feature-rich and powerful rule-ba

Ragunath Jawahar 3.2k Dec 29, 2022
A lightweight, simplified form validation library for Android

A lightweight, simplified form validation library for Android

İbrahim Süren 91 Nov 9, 2022
Compose easy forms validation library

Compose EasyForms Focus on building your form UI while the library do the heavy work for you. Features Built in support for most of the Form widgets i

Kosh Sergani 24 Jul 18, 2022
Kotlin validation with a focus on readability

kommodus Kotlin validation with a focus on readability import com.github.kommodus.constraints.* import com.github.kommodus.Validation data class Test

Serhii Shobotov 0 Dec 12, 2021
Sample project displaying process of OTP validation using firebase

OTP-Validation-using-firebase Sample project displaying process of OTP validation using firebase Screenshots Concepts used Integrated Firebase sdk for

Ankita Gaba 2 Jun 18, 2022
A simple library for validating user input in forms using annotations.

ValidationKomensky for Android A simple library for validating user input in forms using annotations. Features: Validate all views at once and show fe

Inmite s.r.o. 512 Nov 20, 2022
High level parsing to ensure your input is in the right shape and satisfies all constraints that business logic requires.

Parsix High level parsing to ensure your input is in the right shape and satisfies all constraints that business logic requires. It is highly inspired

null 190 Oct 16, 2022
Native solution for common React Native problem of focused views being covered by soft input view.

react-native-avoid-softinput Native solution for common React Native problem of focused views being covered by soft input view. It is solved by listen

Mateusz Mędrek 312 Jan 2, 2023
Type safe intent building for services and activities

#IntentBuilder Type safe intent building for services and activities. IntentBuilder is a type safe way of creating intents and populating them with ex

Emil Sjölander 348 Oct 10, 2022