A Glitch in the Data - a no-nonsense android library for form validation/validate and string matching

Overview

A Glitch in the Data

A no-nonsense Android Library for Form Validation and String Matching

Build

- -
📺 Preview
📱 Compatibility
💻 Usage
📩 Download
📋 Features
🧾 Changelog
🏆 Credits
👨‍💻 Contribution
⚖️ License

Preview

ScreenShot

Compatibility

Android Jellybean 4.1+/SDK 16+

Usage

Simple usage:

Forms

    val element = FormElement(edittext1)  
    val form = FormValidator()  
    form.add(element).withRule(Rules.Digit())  
    Log.d("TAG","${form.isValid()}")

This is true when text is digit only.

Strings

    val stringValidator = StringValidator().addWithRule("111", Rules.Digit())  
      .addWithRule("a1aa", Rules.Decimal())  
    println(stringValidator.isValid())

This simple type of validation is passive and only should be used for debugging mode or for checking strings, but you can validate your form in active way, using active way library will manufacture a TextWatcher for each of elements and as you type validation is checked and error message is shown.

    val form = FormValidator() 
    form.addWithRule(FormElement(edittext1).error("sss"),  
      Rules.Length.Min(3, "You must enter at least 3 characters"),  
      Rules.AlphaNumeric("Alpha Numeric Only"))  
    form.addWithRule(FormElement(edittext2),  
      Rules.Length.Min(10, "You can not enter less than 10 characters"),  
      Rules.Digit("You can only enter digits"))  
    form.addWithRule(FormElement(edittext3), Rules.NotEmpty("You can not enter empty text"))  
      
    form.addSubmitButton(findViewById(R.id.submitButton))  
      
    form.activeCheck()

Elements also can have name which are used when you want to know exactly which element is valid or not, where states is a MutabeMap<String, Boolean> with a pair of element name and element validity.

    FormElement(edittext1, "myelementname")
    val states = form.getFormState()

Elements can have general error message:

    FormElement(...).error("enter a proper input")

Alternatively error messages can be different for each rule:

    form.addWithRule(FormElement(edittext2),  
      Rules.Length.Min(10, "You can not enter less than 10 characters"),  
      Rules.Digit("You can only enter digits"))

For the sake of brevity and convenience elements and rules can be added in different kind of ways: you can pass a single element, variable argument of elements or a List of elements

    form.add(element,element,...)
    form.add(elementList)

Above format is also applied when adding elements with rule or alternatively you can create a Map with pair of element and rules and pass it as an argument.

One thing to consider is you can also add (a) rule/rules as global rule for elements but you should not combine this with different rules for each element. you either set a global rule for all elements or set a different rule for each element.

    form.add(...).add(...).withRule(...)

For forms a submit button also can be added, adding a submit button makes it disabled. submit button will be enabled when every element of form is valid.

      form.addSubmitButton(button)

Currently following Rules are supported:

  • Digit - (1, 2225, 12)
  • Decimal - (1.1, 0.5, .5)
  • Not Empty - (returns true when input is not empty)
  • Length - (returns true only when exactly equal to provided length)
  • Minimum Length - (returns true when length is equal or bigger than minimum)
  • Maximum Length - (returns true when length is less than or equal maximum)
  • Regex - (custom regex pattern)
  • Custom - (custom logic provided by you)
  • Arabic Numbers - (۰, ۹)
  • Persian Numbers - (٠-٩)
  • Persian Text - (سلام دنیا)
  • Iranian Mobile Numbers - (09111257622)
  • Iranian National Code
  • Email
  • URL
  • ...

You can use custom rule like this:

    form.addWithRule(FormElement(input), Rules.Custom {  
      val isValid = false  
      //your logic here  
      return@Custom isValid  
    })

Notice

This library doesn't delete whitespace so 125 is a digit but 111 25 is not a digit (sometime mobile number is typed in that format with spaces between every three number) if you want to check if the second one is digit or not you either should use ContainsDigit rule or force library to ignore whitespace which I do not recommend because of obvious reasons.

    val form = FormValidator().ignoreWhiteSpace(true)

Null Safety

I tried my best to make it null safe but you can always force-pass a null argument, if you try that library will slap you in the face with a NullPointerException.

Download

Gradle

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
	implementation 'com.github.yamin8000:A_Glitch_in_the_Data:0.0.2'
}

Maven

Step 1. Add the JitPack repository to your build file

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Step 2. Add the dependency

	<dependency>
	    <groupId>com.github.yamin8000</groupId>
	    <artifactId>A_Glitch_in_the_Data</artifactId>
	    <version>Tag</version>
	</dependency>

Features

  • Form Validation
  • String Validation
  • Validate Form and Strings using different rules
  • Currently supported rules: Alpha Numeric (English), Digit, Decimal, Not Empty, Length (exact, min, max), Arabic Number, Persian Number, Persian Text, Iranian Mobile Numbers, Iranian National Code, ...
  • Regex Rule with custom regex pattern
  • Custom Rule with custom logic
  • Currently only EditText, TextInputEditText, TextInputLayout are supported
  • Submit button subscription

Changelog

  • 0.0.1 first build
  • 0.0.2 bug fix

Credits

Inspired by Dhaval2404 / android-form-validation

Contribution

Any contribution is welcome, For Persian speakers ( 🇮🇷 🇦🇫 ) creating issues in Persian is also allowed.

License

yamin8000/A_Glitch_in_the_Data is licensed under the GNU General Public License v3.0

Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights.

You might also like...
Clean MVVM with eliminating the usage of context from view models by introducing hilt for DI and sealed classes for displaying Errors in views using shared flows (one time event), and Stateflow for data

Clean ViewModel with Sealed Classes Following are the purposes of this repo Showing how you can remove the need of context in ViewModels. I. By using

FirestoreCleanArchitectureApp is an app built with Kotlin and Firestore that displays data in real-time using the MVVM Architecture Pattern. For the UI it uses Jetpack Compose,  Android's modern toolkit for building native UI.
FirestoreCleanArchitectureApp is an app built with Kotlin and Firestore that displays data in real-time using the MVVM Architecture Pattern. For the UI it uses Jetpack Compose, Android's modern toolkit for building native UI.

FirestoreCleanArchitectureApp FirestoreCleanArchitectureApp is an app built with Kotlin and Cloud Firestore that displays data in real-time using Andr

Accounting-App - An Android app built with Kotlin, Material, Jetpack Compose, Hilt, Room, Coroutines, Data-Store, MVVM-Clean Architecture and JUnit tests Algorithms and data structures in Kotlin.
Algorithms and data structures in Kotlin.

Here you can find the most common algorithms and data structures written in Kotlin. The goal of this project is to create the most eloquent implementa

A clean-aesthetically pleasing Measuring Application, which uses relevant sensors-converts raw sensor data into human readable formatted outputs-and displays accurate measurements.
A clean-aesthetically pleasing Measuring Application, which uses relevant sensors-converts raw sensor data into human readable formatted outputs-and displays accurate measurements.

Measure App A clean-aesthetically pleasing Measuring Application, which uses relevant sensors-converts raw sensor data into human readable formatted o

This repository is a simple humidity and temperature dashboard to present data from sensors on your phone
This repository is a simple humidity and temperature dashboard to present data from sensors on your phone

ChilliBook This repository is a simple humidity and temperature dashboard to present data from sensors on your phone. It uses Bluetooth LE and an ESP3

An AutoValue extension that generates binary and source compatible equivalent Kotlin data classes of AutoValue models.
An AutoValue extension that generates binary and source compatible equivalent Kotlin data classes of AutoValue models.

AutoValue Kotlin auto-value-kotlin (AVK) is an AutoValue extension that generates binary-and-source-compatible, equivalent Kotlin data classes. This i

Basic application that uses Retrofit, Moshi and Coil libraries to parse data from web API

DogAlbum_Api_CodeThrough Basic application that uses Retrofit, Moshi and Coil libraries to parse data from web API This folder contains the completed

This repo contains my solutions to some data structures and algorithms problems on leetcode.

DSA Playground This repository contains solutions to dsa problems in kotlin. NOTE: This file will get long, please consider using CtrlF DSA With Kun

Comments
  • Configure Renovate

    Configure Renovate

    WhiteSource Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • gradle.properties (gradle)
    • settings.gradle (gradle)
    • build.gradle (gradle)
    • A_Glitch_in_the_Data/build.gradle (gradle)
    • app/build.gradle (gradle)
    • gradle/wrapper/gradle-wrapper.properties (gradle-wrapper)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation
    • If semantic commits detected, use semantic commit type fix for dependencies and chore for all others
    • Ignore node_modules, bower_components, vendor and various test/tests directories
    • Autodetect whether to pin dependencies or maintain ranges
    • Rate limit PR creation to a maximum of two per hour
    • Limit to maximum 10 open PRs at any time
    • Group known monorepo packages together
    • Use curated list of recommended non-monorepo package groupings
    • Fix some problems with very old Maven commons versions
    • Ignore spring cloud 1.x releases
    • Ignore web3j 5.0.0 release
    • Ignore http4s digest-based 1.x milestones
    • Use node versioning for @types/node
    • Limit concurrent requests to reduce load on Repology servers until we can fix this properly, see issue 10133
    • Do not upgrade from Alpine stable to edge

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 6 Pull Requests:

    Update dependency androidx.constraintlayout:constraintlayout to v2.1.3
    Update dependency androidx.appcompat:appcompat to v1.4.1
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.appcompat-appcompat-1.x
    • Merge into: master
    • Upgrade androidx.appcompat:appcompat to 1.4.1
    Update dependency androidx.core:core-ktx to v1.7.0
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.core-core-ktx-1.x
    • Merge into: master
    • Upgrade androidx.core:core-ktx to 1.7.0
    Update dependency com.android.tools.build:gradle to v7.1.2
    • Schedule: ["at any time"]
    • Branch name: renovate/com.android.tools.build-gradle-7.x
    • Merge into: master
    • Upgrade com.android.tools.build:gradle to 7.1.2
    Update dependency com.google.android.material:material to v1.5.0
    Update dependency gradle to v7.4.1
    • Schedule: ["at any time"]
    • Branch name: renovate/gradle-7.x
    • Merge into: master
    • Upgrade gradle to 7.4.1

    🚸 Branch creation will be limited to maximum 2 per hour, so it doesn't swamp any CI resources or spam the project. See docs for prhourlylimit for details.


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by WhiteSource Renovate. View repository job log here.

    opened by renovate[bot] 1
Releases(0.0.4)
Owner
YaMiN
Android, Kotlin, Java, C#, Raspberry Pi enthusiast
YaMiN
LoginValidation - A simple login app with password validation

LoginValidation A simple login app with password validation License Copyright 20

Srihitha Tadiparthi 2 Feb 18, 2022
Nice String in Kotlin

Nice String We'll say a string is nice if at least two of the following conditio

Bunyod Rafikov 0 Dec 28, 2021
FizzBuzzKotlin - A function fizzBuzz to generate a list of string based on the input number

FizzBuzzKotlin write a function fizzBuzz to generate a list of string based on t

gson 0 Feb 12, 2022
Plannr is an organizational platform developed using Java, in the form of an Android app, that helps university students coordinate their everyday routine.

Plannr Plannr is an organizational platform developed using Java, in the form of an Android app, that helps university students coordinate their every

Dana Al Shekerchi 2 Sep 8, 2022
Use Android Data Binding wih Live Data to glue View Model and Android

Gruop-C Spliff Summary Use Android Data Binding wih Live Data to glue View Model and Android. Asynchronous communications implemented with KotlinX Cor

null 2 Nov 21, 2021
Demo Spting REST Service on Kotlin. Works with PostgreSQL via Spring Data. Data initialization provided by liquibase

Spring Boot REST API with Kotlin Spring Boot REST API service. Spring Data with PostgreSQL. Data initialization with Liquibase. Swagger UI Reference D

null 0 Jun 10, 2022
Detailing about the data provided (Data Visualization Application)

Detailing about the data provided (Data Visualization Application): • In the application, the data provided in the CSV is used for the Scatter plot cr

Neha Sharma 0 Nov 20, 2021
A library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from ResultSet's rows).

SqlObjectMapper This is a library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from Re

Qualified Cactus 2 Nov 7, 2022
Small kotlin library for persisting _single instances_ of kotlin data classes

PerSista Small library for persisting single instances of kotlin data classes. NB: PerSista uses typeOf() internally which is marked as @ExperimentalS

Eric Donovan 5 Nov 13, 2022