All Projects → pchmn → AndroidVerify

pchmn / AndroidVerify

Licence: Apache-2.0 license
Android library designed for rapid and customizable form validation.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to AndroidVerify

Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (+209.76%)
Mutual labels:  form-validation, easy-to-use
eins-modal
Simple to use modal / alert / dialog / popup. Created with pure JS. No javascript knowledge required! Works on every browser and device! IE9
Stars: ✭ 30 (-26.83%)
Mutual labels:  easy-to-use
wakib-emacs
Emacs Starter Kit based on Wakib keybindings
Stars: ✭ 28 (-31.71%)
Mutual labels:  easy-to-use
ctxmenu
Tiny and customizable context menu generator
Stars: ✭ 20 (-51.22%)
Mutual labels:  easy-to-use
dhtml2pdf
Simple, free and very easy to use PHP API that allows you to see, download or get the binary of the PDF generated from the HTML of an URL.
Stars: ✭ 27 (-34.15%)
Mutual labels:  easy-to-use
react-form-validation
A simple and declarative way to validate your forms in React
Stars: ✭ 24 (-41.46%)
Mutual labels:  form-validation
ATGValidator
iOS validation framework with form validation support
Stars: ✭ 51 (+24.39%)
Mutual labels:  form-validation
QArchive
Async C++ Cross-Platform library that modernizes libarchive using Qt5 🚀. Simply extracts 7z 🍔, Tarballs 🎱 and other supported formats by libarchive. ❤️
Stars: ✭ 66 (+60.98%)
Mutual labels:  easy-to-use
thread-pool
BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
Stars: ✭ 1,043 (+2443.9%)
Mutual labels:  easy-to-use
ember-validity-modifier
Ember Octane addon to add custom validity (form validation) to form fields
Stars: ✭ 28 (-31.71%)
Mutual labels:  form-validation
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (-9.76%)
Mutual labels:  form-validation
penelope
Penelope Shell Handler
Stars: ✭ 291 (+609.76%)
Mutual labels:  easy-to-use
Raunaksingh-hacktober-2020
Welcome to Hackertober fest 2020
Stars: ✭ 7 (-82.93%)
Mutual labels:  easy-to-use
envalid
Envalid is a framework agnostic and fluent server side form validation package for PHP
Stars: ✭ 23 (-43.9%)
Mutual labels:  form-validation
Easy-HotSpot
Easy HotSpot is a super easy WiFi hotspot user management utility for Mikrotik RouterOS based Router devices. Voucher printing in 6 ready made templates are available. Can be installed in any PHP/MySql enabled servers locally or in Internet web servers. Uses the PHP PEAR2 API Client by boenrobot.
Stars: ✭ 45 (+9.76%)
Mutual labels:  easy-to-use
recaptcha2
Easy verifier for google reCAPTCHA version 2 for Node.js and Express.js
Stars: ✭ 48 (+17.07%)
Mutual labels:  form-validation
vue-formly-buefy
The declarative way to create and validate forms.
Stars: ✭ 18 (-56.1%)
Mutual labels:  form-validation
Effortless-SPIFFS
A class designed to make reading and storing data on the ESP8266 and ESP32 effortless
Stars: ✭ 27 (-34.15%)
Mutual labels:  easy-to-use
LiteNetwork
A simple and fast .NET networking library compatible with .NET Standard 2, .NET 5, 6 and 7.
Stars: ✭ 66 (+60.98%)
Mutual labels:  easy-to-use
Xception-with-Your-Own-Dataset
Easy-to-use scripts for training and inferencing with Xception on your own dataset
Stars: ✭ 51 (+24.39%)
Mutual labels:  easy-to-use

AndroidVerify

Android library designed for rapid and customizable form validation.

Release

Demo

Download sample-v1.0.2.apk

Setup

To use this library your minSdkVersion must be >= 15.

In your project level build.gradle :

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

In your app level build.gradle :

dependencies {
    compile 'com.github.pchmn:AndroidVerify:1.0.2'
}      

Usage

You can use AndroidVerify with any View that extends the original EditText (such as MaterialEditText for example).

With XML

You just have to wrap your EditText with an InputValidator view. Example for an email and a custom regex :

<com.pchmn.androidverify.InputValidator
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:required="true"
    app:requiredMessage="Email required">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:hint="Email"/>

</com.pchmn.androidverify.InputValidator>
            
<com.pchmn.androidverify.InputValidator
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:regex="^[0-9]{4}$"
    app:errorMessage="4 digits only">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Regex 4 digits (custom error msg)"/>

</com.pchmn.androidverify.InputValidator>            

InputValidator will automatically recognized textEmailAdress, phone and number inputType and use the appropriate validator, like in the example with the email field.
If you don't specify an errorMessage or a requiredMessage, predefined messages will be shown if the field is not valid.

Then validate your form :

// initiate from an activity
// 'this' represents an Activity
// you can specify if you want to show error messages or not
Form form = new Form.Builder(this)
    .showErrors(true)
    .build();

// or initiate from a fragment or from what you want by providing your own root view
Form form = new Form.Builder(getContext(), rootView)
    .showErrors(true)
    .build();

// validate the form
if(form.isValid()) {
    // the form is valid
}
else {
    // the form is not valid
}        

With Java

You can create programmatically InputValidator without passing by XML (see all Builder methods) :

// create the validator with the Builder
// emailEditText is the EditText to validate 
// 'this' represents a Context
InputValidator emailValidator = new InputValidator.Builder(this)
    .on(emailEditText)
    .required(true)
    .validatorType(InputValidator.IS_EMAIL)
    .build();
                
// create the form and add the validator
Form form = new Form.Builder(this)
    .addInputValidator(emailValidator)
    .build();
    
// validate the form
if(form.isValid()) {
    // the form is valid
}
else {
    // the form is not valid
}

You can create programmatically without using the Builders, but it is safer and quicker to use Builders.

Attributes

InputValidator

All the attributes that can be used with the InputValidator view. They can be used in XML or in Java with setters :

Attribute Type Description
app:required boolean Whether the field is required or not
app:validator enum Use a validator type predefined by FormValidator. You can use isEmail, isPhoneNumber, isNumeric, isUrl or isIP
app:minLength int The minimum length of the field
app:maxLength int The maximum length of the field
app:minValue int The minimum value of the field (must be numeric)
app:maxValue int The maximum value of the field (must be numeric)
app:regex string Use a regex to validate a field
app:identicalAs reference id The id of an EditText to which the field must be equal
app:errorMessage string The message to display if the field is not valid
app:requiredMessage string The message to display if the field is empty but was required. It implies that the field is required

Form

All the attributes that can be used with the Form view. They can be used in XML or in Java with setters :

Attribute Type Default Description
app:showErrors boolean true Whether the errors must be shown on each EditText or not

Advanced Usage

Use a custom validator

You can use a custom validator for an InputValidator :

// the InputValidator was present in the XML layout
InputValidator inputValidator = (InputValidator) findViewById(R.id.input_validator);
// your custom validator must extends AbstractValidator class
inputValidator.setCustomValidator(new AbstractValidator() {
    @Override
    public boolean isValid(String value) {
        return value.equals("ok man");
    }
              
    @Override
    public String getErrorMessage() {
        return "This field must be equals to 'ok man'";
    }
});


// or create your InputValidator with the Builder
InputValidator inputValidator = new InputValidator.Builder(this)
    .on(anEditText)
    .customValidator(new AbstractValidator() {
        @Override
        public boolean isValid(String value) {
            return value.equals("ok man");
        }
                  
        @Override
        public String getErrorMessage() {
            return "This field must be equals to 'ok man'";
        }
    });
    .build();

Use the Form view in XML

If you want, you can use a Form view directly in XML. This view extends LinearLayout. It must wrap all the fields you want to check.

It can be useful for these reasons :

  • You don't have to instantiate a Form object before validate the form
  • It will be easier to identify a form in your XML layout
  • You can use two different and independent forms in the same XML layout

XML

    <!-- form1 -->
    <com.pchmn.androidverify.Form
        android:id="@+id/form1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:showErrors="false">

        <!-- email -->
        <com.pchmn.androidverify.InputValidator
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email"/>

        </com.pchmn.androidverify.InputValidator>

        <!-- password -->
        <com.pchmn.androidverify.InputValidator
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:required="true"
            app:minLength="6">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password (6 char. min) *" />

        </com.pchmn.androidverify.InputValidator>

    </com.pchmn.androidverify.Form>
    <!-- /form1 -->

    <!-- form2 -->
    <com.pchmn.androidverify.Form
        android:id="@+id/form2"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- phone number -->
        <com.pchmn.androidverify.InputValidator
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:required="true">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:hint="Phone number *"/>

        </com.pchmn.androidverify.InputValidator>

        <!-- age -->
        <com.pchmn.androidverify.InputValidator
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:minValue="12">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:hint="Age (12 min)" />

        </com.pchmn.androidverify.InputValidator>

    </com.pchmn.androidverify.Form>
    <!-- /form2 -->

Validate the forms

// get the forms
// you don't have to instantiate them because they already know the fields they have to validate
Form form1 = (Form) findViewById(R.id.form1);
Form form2 = (Form) findViewById(R.id.form2);

// validate form1
if(form1.isValid()) {
    // form1 is valid
}

// validate form2
if(form2.isValid()) {
    // form2 is valid
}

Builders method

It is recommended to use the builders to create Form and InputValidator views programmatically in order to prevent some errors. All the attributes for the two views are supported by the builders.

InputValidator builder

InputValidator inputValidator = new InputValidator.Builder(this)
    // methods
    .build();
Method Return value Description
InputValidator.Builder(Context context) InputValidator.Builder The constructor of the builder
on(EditText editText) InputValidator.Builder The EditText to validate
required(boolean required) InputValidator.Builder Whether the field is required or not
validatorType(int type) InputValidator.Builder Use a validator type predefined by FormValidator. You can use InputValidator.IS_EMAIL, InputValidator.IS_PHONE_NUMBER, InputValidator.IS_NUMERIC, InputValidator.IS_URL or InputValidator.IS_IP
customValidator(AbstractValidator validator) InputValidator.Builder Use a custom validator
minLength(int length) InputValidator.Builder The minimum length of the field
maxLength(int length) InputValidator.Builder The maximum length of the field
minValue(int value) InputValidator.Builder The minimum value of the field (must be numeric)
maxValue(int value) InputValidator.Builder The maximum value of the field (must be numeric)
regex(String regex) InputValidator.Builder Use a regex to validate a field
identicalAs(int id) InputValidator.Builder The id of an EditText to which the field must be equal
identicalAs(EditText editText)` InputValidator.Builder An other EditText to which the field must be equal
errorMessage(String message) InputValidator.Builder The message to display if the field is not valid
requiredMessage(String message) InputValidator.Builder The message to display if the field is empty but was required
build() InputValidator Create the InputValidator object

Form builder

Form form = new Form.Builder(this)
    // methods
    .build();
Method Return value Description
Form.Builder(Activity activity) Form.Builder First constructor of the builder
Form.Builder**(Context context, View rootView) Form.Builder Second constructor of the builder
Form.Builder(Context context) Form.Builder Third constructor of the builder. Be aware of possibly inflating errors using this constructor
addInputValidator(InputValidator validator) Form.Builder Add an InputValidator
showErrors(boolean show) Form.Builder Whether the errors must be shown on each EditText or not
build() Form Create the Form object

Sample

A sample app with some use cases of the library is available on this link

Credits

License

Copyright 2017 pchmn

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].