All Projects → julianraj → ValidatedTextInputLayout

julianraj / ValidatedTextInputLayout

Licence: Apache-2.0 License
An extension to Android Design Support library's TextInputLayout with integrated validation support

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to ValidatedTextInputLayout

ember-changeset-conditional-validations
Conditional validations for ember-changeset-validations
Stars: ✭ 26 (-51.85%)
Mutual labels:  validation
fqdn
RFC-compliant FQDN validation and manipulation for Python.
Stars: ✭ 23 (-57.41%)
Mutual labels:  validation
react-form-validation-demo
React Form Validation Demo
Stars: ✭ 88 (+62.96%)
Mutual labels:  validation
openapi-lint-vscode
OpenAPI 2.0/3.0.x intellisense, validator, linter, converter and resolver extension for Visual Studio Code
Stars: ✭ 47 (-12.96%)
Mutual labels:  validation
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (+48.15%)
Mutual labels:  validation
verum-php
Server-Side Validation Library for PHP
Stars: ✭ 17 (-68.52%)
Mutual labels:  validation
rdf-validate-shacl
Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
Stars: ✭ 61 (+12.96%)
Mutual labels:  validation
valid8
Valid8 - Super Simple Bootstrap Form Valiation
Stars: ✭ 17 (-68.52%)
Mutual labels:  validation
ng2-multi-step-wizard-ui-router1
Series 3: Tutorials on creating an Angular 2 Multi-Step Wizard using UI-Router 1.0 and TypeScript 2.0.10
Stars: ✭ 33 (-38.89%)
Mutual labels:  validation
peppermint
Declarative data validation framework, written in Swift
Stars: ✭ 37 (-31.48%)
Mutual labels:  validation
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-68.52%)
Mutual labels:  validation
cnpj
🇧🇷 Format, validate and generate CNPJ numbers in Node & Deno
Stars: ✭ 26 (-51.85%)
Mutual labels:  validation
fastify-response-validation
A simple plugin that enables response validation for Fastify.
Stars: ✭ 20 (-62.96%)
Mutual labels:  validation
formalizer
React hooks based form validation made for humans.
Stars: ✭ 12 (-77.78%)
Mutual labels:  validation
NZ-Bank-Account-Validator
A small, zero dependency NZ bank account validation library that runs everywhere.
Stars: ✭ 15 (-72.22%)
Mutual labels:  validation
validatedb
Validate on a table in a DB, using dbplyr
Stars: ✭ 15 (-72.22%)
Mutual labels:  validation
liquibase-linter
Quality control for your Liquibase scripts
Stars: ✭ 15 (-72.22%)
Mutual labels:  validation
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (-35.19%)
Mutual labels:  validation
exvalibur
Elixir Validator Generator
Stars: ✭ 14 (-74.07%)
Mutual labels:  validation
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (-55.56%)
Mutual labels:  validation

ValidatedTextInputLayout Download Circle CI

An extension to android design support library's TextInputLayout with validation support

Demo

Demo

Note: v1.0.0-beta1 adds migration to androidx and to kotlin from java. Upgrading to beta might break your code.

Features

  • AutoValidation
    Validate the input field as the text changes.
    input.autoValidate(true) If false you need to call the validate() method explicitly for validation.
    OR
    use xml attribute autoValidate as true or false.

  • AutoTrim
    input.getValue() will return the value of input field after removing leading and trailing white spaces

    input.autoTrimValue(true) OR
    use xml attribute autoTrim as true or false.

  • Add Validators
    You can add multiple validators to a single input field.
    input.addValidator(/* Your first Validator class goes here */) input.addValidator(/* Your second Validator class goes here */)

  • Clear Validators
    Removes all the validators associated with the input field.
    input.clearValidators()

  • Default Available Validators

    • RequiredValidator
      Validates the input field as required. i.e. empty value is not valid.
      input.addValidator(RequiredValidator("Your error message")) OR
      use xml attribute isRequired as true or false.
      The default message will be "This field is required."
      For custom message you can use xml attribute requiredValidationMessage

    • LengthValidator
      Validates the input field against minimum and maximum length specified.
      input.addValidator(LengthValidator(8 /* Max Length */, "Your error message")) input.addValidator(LengthValidator(4 /* Min Length */, *8 /* Max Length */, "Your error message")) OR
      use xml attributes minLength and maxLength with default values being "zero" and "indefinite" respectively.
      The default message will be one of following

      • The input must have length between "minLength" and "maxLength".
      • The input length must be greater than or equal to "minLength".
      • The input length must be less than or equal to "maxLength".
        based on your values for minLength and maxLength attributes.
        For custom message you can use xml attribute lengthValidationMessage
    • RegexValidator
      Validates the input field against provided regular expression. Equivalent to String.matches()
      input.addValidator(new RegexValidator("your_regex", "Your error message")) OR
      use xml attribute regex to set your regular expression.
      The default message will be "The field value does not match the required format."
      For custom message you can use xml attribute regexValidationMessage

    • DependencyValidator
      Validates the input field as per the dependency type with the input field it depends on.
      If input1 depends on input2 with dependency type TYPE_EQUAL: (i.e. input1 .getValue() must be equal to input1.getValue())
      input1.addValidator(new DependencyValidator(input2, TYPE_EQUAL, "Your error message"))

  • Custom Validators
    You can create your own validators to use with ValidatedTextInputLayout just by extending the BaseValidator class.
    You need to call the super() method with the desired message and override isValid() method to return true or false;

Example: Validator class to check if field value contains character sequence "xyz"

    class MyValidator(errorMessage: String,
                      callback: ValidationCallback? = null): BaseValidator(errorMessage, callback) {
        override fun isValid(text: String): Boolean {
            return text.contains("xyz")
        }
    }
  • Validation Callback You can add callbacks to the validators from constructor or a setter using the ValidationCallback class.

Usage

  • Maven

     <dependency>
           <groupId>com.julianraj</groupId>
           <artifactId>validatedtextinputlayout</artifactId>
           <version>1.0.0-beta1</version>
           <type>pom</type>
     </dependency>
    
  • Gradle

     compile 'com.julianraj:validatedtextinputlayout:1.0.0-beta1'
    
  • You can use and style it similar to Android Design Library's TextInputLayout

     <com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout
             android:id="@+id/username"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             validation:autoTrim="true"
             validation:isRequired="true"
             validation:requiredValidationMessage="Your error message here.">
     
             <com.google.android.material.textfield.TextInputEditText
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:hint="Username"
                 android:singleLine="true"/>
     
     </com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout>
     
     <com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout
             android:id="@+id/password"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             validation:autoValidate="true"
             validation:lengthValidationMessage="Your error message here."
             validation:maxLength="8"
             validation:minLength="4">
     
             <com.google.android.material.textfield.TextInputEditText
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:hint="Password (AutoValidated)"
                 android:inputType="textPassword"
                 android:singleLine="true"/>
     
     </com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout>
     
     <com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout
             android:id="@+id/email"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             validation:autoTrim="true"
             validation:regex="^[a-z0-9._%+-]+@(?:[a-z0-9-]+[.])+[a-z]{2,}$"
             validation:regexValidationMessage="Your error message here">
     
             <com.google.android.material.textfield.TextInputEditText
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:hint="Email"
                 android:singleLine="true"/>
     </com.julianraj.validatedtextinputlayout.ValidatedTextInputLayout>
    

License

Copyright 2016 Julian Raj Manandhar

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.  
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].