GithubHelp home page GithubHelp logo

validationhelper's Introduction

ValidationHelper

Library to define all validation condition at single place and handle all validation in a class in simple way Follow below step to add this in to your project

Step 1. Add the dependency

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add it in your root build.gradle at the end of repositories:

dependencies {
        implementation 'com.github.bhoomit11:ValidationHelper:1.0.0'
}

Create object of validation helper in class which you want to use validations

private val validationHelper: ValidationHelper by lazy {
    ValidationHelper(
        context = this,
        anim = null, // Pass custom animation if you need, if not then pass null, shake anim is default
        putStarInRequired = true // Set this as true if * needed in required fields in you project
    )
}

"anim" is animation object you want when validation error accurs, default is shake error animation is there in library "putStarInRequired" set true if you want * in your required fields in your form

You can add different validation like this in validationHelper

 /*
     * Simple required field validation
     */
    validationHelper.addRequiredValidation(
        textInputLayout = tilName,
        blankMsg = "Enter full name" // Error message if blank
    )

    /*
     * Email field validation
     */
    validationHelper.addEmailValidation(
        textInputLayout = tilEmail,
        blankEmailMsg = "Enter email address", // Error message if blank
        invalidEmailMsg = "Enter valid email", // Error message if invalid
        isRequired = true
    )

    /*
     * Mobile field validation
     */
    validationHelper.addMobileValidation(
        textInputLayout = tilMobile,
        blankMobileNumberMsg = "Enter mobile number", // Error message if blank
        invalidMobileNumberMsg = "Enter valid mobile number", // Error message if invalid
        isRequired = true,
        mobileNumberPattern = MOBILE_PATTERN // add your pattern if you need, but default is available
    )

    /*
     * Custom field validation (Add you own pattern validation)
     */
    validationHelper.addCustomePatternValidation(
        textInputLayout = tilBankAccountNumber,
        patternMismatchMsg = "Invalid bank account number", // Error message if pattern not match
        pattern = ACCOUNT_NUMBER_PATTERN
    )

    /*
     * Password field validation, with strong password enable option
     */
    validationHelper.addPasswordValidation(
        textInputLayout = tilPassword,
        blankPasswordMsg = "Enter password", // Error message if blank
        weakPasswordMSg = "Enter strong password", // Error message if not strong password
        isRequired = true,
        isStrong = true,
        strongPattern = STRONG_PASSWORD_PATTERN // add your pattern if you need, but default is available
    )

    /*
     * confirm password field validation
     */
    validationHelper.addConfirmPasswordValidation(
        textInputLayout = tilPassword, // Add this param as your password field
        confirmTextInputLayout = tilConfirmPassword, // Add this param as your confirm password field
        mismatchPasswordMsg = "Password and confirm password must be same" // Error message if not matched
    )

to clear out all validation added in validationHelper class

validationHelper.clearAll() // If you want to clear all previous validations added

to validate added validation

button.setOnClickListener {
        if (validationHelper.validateAll()) {
            // Put you logic here if all validations are passed
        }
    }

Checkout sample for more info.

validationhelper's People

Contributors

bhoomit11 avatar bhumitbelani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.