Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

Overview

MaskFormatter

MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter

Animated

Mask should be built from characters listed below (java regex associated to character given after colon):

'9': '[0-9]',
'8': '[0-8]',
'7': '[0-7]',
'6': '[0-6]',
'5': '[0-5]',
'4': '[0-4]',
'3': '[0-3]',
'2': '[0-2]',
'1': '[0-1]',
'0': '[0]',

'*': '.',
'W': '\W',
'd': '\d',
'D': '\D',
's': '\s',
'S': '\S',

'A': '[A-Z]',
'a': '[a-z]',
'Z': '[A-ZÇÀÁÂÃÈÉÊẼÌÍÎĨÒÓÔÕÙÚÛŨ]',
'z': '[a-zçáàãâéèêẽíìĩîóòôõúùũüû]',
'@': '[a-zA-Z]',
'#': '[a-zA-ZçáàãâéèêẽíìĩîóòôõúùũüûÇÀÁÂÃÈÉÊẼÌÍÎĨÒÓÔÕÙÚÛŨ]',

'%': '[A-Z0-9]',
'w': '[a-zA-Z0-9]'

Usage

In your build.gradle:

dependencies {
    compile 'com.azimolabs.maskformatter:maskformatter:0.2'
}

Library is distributed via jCenter Maven repository. Make sure that you have it in your root gradle config:

allprojects {
    repositories {
        jcenter()
    }
}

Then you can use it like this:

public MainActivity extends Activity {

     private static final IBAN_MASK = "AA 99 9999 AAAA wwww wwww wwww";

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.sample_layout);

          EditText ibanEditText = (EditText) findViewById(R.id.etIban);
          MaskFormatter ibanMaskFormatter = new MaskFormatter(IBAN_MASK, ibanEditText);
          ibanEditText.addTextChangedListener(ibanMaskFormatter);
     }

}

And make sure that you disabled suggestions from used EditText:

<EditText
    android:id="@+id/etIban"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text|textNoSuggestions" />

License

	Copyright (C) 2016 AzimoLabs

    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.

Towards financial services available to all

We’re working throughout the company to create faster, cheaper, and more available financial services all over the world, and here are some of the techniques that we’re utilizing. There’s still a long way ahead of us, and if you’d like to be part of that journey, check out our careers page.

Comments
  • Repository jcenter deprecated

    Repository jcenter deprecated

    Due to the jcenter repository is deprecated we need this library in another repository in order to continue using it; it would be nice because we are happy whit it in our project. Thank you.

    opened by AlvaroMonk 2
  • Preserve password input type

    Preserve password input type

    If I set an EditText to have an input-type of numberPassword or textPassword I want the "dot masking" to be preserved. Right now the setInputTypeBasedOnMask method removes the dot masking. (See the GIFs below for a demo on an emulator). This fixes issue #9.

    My use case for this is masking a user's social security number in an app (for which I use it in combination with PR #6 which added dashes as a replacement for the space character).

    If a user enters the social security number: "123-45-6789" it masks the numbers and the dashes.

    It's not an ideal way of doing things because I don't want to see the dashes or spaces masked with the numbers, but I'd need to use a custom component to handle that and it's not in the scope of this library or this PR.

    But it works for the app I use it in.

    This may be a special use case and may not fit the intent of this library, but let me know what you think, thanks!

    Problem: The EditText has a password on the input-type (see activity_main.xml). problem

    Fix: Any variation of InputType.PASSWORD is preserved. preserving-password

    opened by dvoiss 2
  • Add option for custom mask character

    Add option for custom mask character

    This PR adds the ability to pass in a custom mask character to a second constructor. In the tests this character is a "-" and I use it for phone-number formatting in a project.

    There is a minor change in functionality in MaskFormatter. I've changed:

    replaceAll("\\s", "")
    

    which is now replaced with:

    replaceAll(String.valueOf(maskCharacter), "")

    I'm not sure if there's a use case with the library where there is more than one white space character that needs to be replaced, let me know if so and I'll update this PR.

    This PR addresses an open issue: #4. Let me know what you think, cheers!

    opened by dvoiss 2
  • An EditText with an inputType of

    An EditText with an inputType of "password" should be masked.

    My use case is for a user entering a social security number in the format 999-99-9999. (I added dashes in PR #6).

    Right now the MaskFormatter#setInputTypeBasedOnMask resets the input-type causing the password type to be lost.

    See the GIF below for a demo where the EditText has numberPassword for the inputType:

        <EditText
            android:id="@+id/ssnChars"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text|textNoSuggestions|numberPassword"/>
    

    problem

    opened by dvoiss 1
  • Moving to a text view should immediately change the keyboard based on the first character in the mask

    Moving to a text view should immediately change the keyboard based on the first character in the mask

    In the GIF below I am using an emulator to enter text into the first field, when I move to the bottom field with mask "999" the text keyboard is active. I end up hitting a character and then the input type changes to the number keyboard.

    issue

    opened by dvoiss 1
  • Multiple masking

    Multiple masking

    Hello, I'm making an app for car license plates but there are multiple license plate types. How can I do them in a single edittext?

    example: 99 A 99999, 99 AA 999 or 99 AAA 999

    opened by nzappstudio 0
  • Problems with prefilled EditTexts

    Problems with prefilled EditTexts

    Hi there,

    I like this lib.

    So I started with a German IBAN.

    The mask is like this: "AA99 9999"

    Now I want to prefill the EditText with "DE".

    But setting it in JAVA (after the TextChangedListener is added) and/or in XML like android:text="DE" the keyboard is wrong.

    The keyboard should only show digits, but it shows alphanumeric.

    Greetings, DaRolla

    opened by DaRolla 0
  • Add support for hardcoded, unmodifable portions of patten

    Add support for hardcoded, unmodifable portions of patten

    Would be great if I could define some portions of pattern unalterable for user. For example I'd like user to enter his mobile phone number but I'd also like to restrict the country, i.e. +48 for Poland. For now I need to move +48 out of the pattern, to separate TextView, but if I'd just do i.e.

     [+48] 999 9999999
    

    and the text in [] would be shown but be unalterable/non-erasable by user, it'd be great. When user finishes I'd like get it all back, incl. +48 part.

    opened by MarcinOrlowski 1
Owner
Azimo Labs
We're the tech team behind Azimo - the faster, cheaper way to send money internationally.
Azimo Labs
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

kpbird 381 Nov 20, 2022
User input masking library repo.

More GIFs [~3 MB] Migration Guide: v.6 This update brings breaking changes. Namely, the autocomplete flag is now a part of the CaretGravity enum, thus

red_mad_robot 1.2k Dec 20, 2022
Androids EditText that animates the typed text. EditText is extended to create AnimatedEditText and a PinEntryEditText.

AnimatedEditText for Android This repository contains AnimatedEditText and TextDrawable all of which extend the behaviour of EditText and implement fe

Ali Muzaffar 439 Nov 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Android Custom View for prevent the view behind on-screen keyboard when edit text is focused

Group Focusable Prevent the view behind on-screen keyboard when edit text is focused in Android UI Download Gradle implementation 'com.akexorcist:grou

Akexorcist 8 Jun 22, 2022
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Txus Ballesteros 354 Nov 28, 2022
A module designed to encapsulate the use of an Android EditText field for gathering currency information from a user. Supports all ISO-3166 compliant locales/currencies.

CurrencyEditText CurrencyEditText is an extension of Android's EditText view object. It is a module designed to provide ease-of-use when using an Edit

Josh Kitchens 335 Dec 25, 2022
Animation effects to text, not really textview

HTextView Animation effects with custom font support to TextView see iOS Effects see Flutter Effects Screenshot type gif Scale Evaporate Fall Line Typ

hanks 5.5k Jan 5, 2023
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

mehran elyasi 4 Feb 14, 2022
💰 A library to dynamically format your EditTexts to take currency inputs

CurrencyEditText A library to dynamically format your EditTexts to take currency inputs. Gradle Dependency Add the dependency to your app's build.grad

Cotta & Cush Limited 115 Dec 28, 2022
Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Provides easy means to validate with dependencies.

android-formidable-validation Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Pr

Linden 147 Nov 20, 2022
A material style input for codes

Material Code input A material style input for put codes Based on Code input field concept by SAMUEL KANTALA How to use Minimal SDK Version 11 Usage w

Adrián Lomas 962 Nov 26, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
A simple Android Tag EditText

TagEditText A simple Android Tag EditText. Setup The easiest way to add the TagEditText library to your project is by adding it as a dependency to you

HearSilent 15 May 5, 2022
An Android App example of how to create a custom EditText using DoubleLinkedList Data Structure

DoubleLinkedListEditText Library This is a library to create an EditText based on the Doubly Linked List data structure so that the user can enter cod

Layon Martins 1 Nov 9, 2021
Awesome Android Typeahead library - User mention plugin, UI widget for auto complete user mention using the at sign (@) like Twitter or Facebook.

android-typeahead Awesome Android Typeahead library - User mention plugin, UI widget for auto complete user mention using the at sign (@) like Twitter

Arab Agile 11 Jun 4, 2019