Coder Social home page Coder Social logo

maskededittext's Introduction

Masked EditText

A library to achieve masked TextView for both RTL and LTR texts.

MaskedEditText - the library for masked input of phone numbers, social security numbers and so on for Android

This project derives from egslava/edittext-mask, but it's been adapted for AndroidX:

  1. filter allowed chars
  2. filter denied chars
  3. use chars from mask in input (ex: use digit '7' in the '+7(XXX)XXX-XX-XX' pattern)
  4. keep hints even when user started typing

So it allows you to use masks for phones, urls, etc.

Enjoy!


Installation

Gradle

dependencies {
    implementation 'com.github.arefbhrn:MaskedEditText:1.0.0'
}

Usage

Add xmlns:app="http://schemas.android.com/apk/res-auto" to your layout xml root:

<com.arefbhrn.maskededittext.MaskedEditText
    android:id="@+id/phone_input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:typeface="monospace"
    android:hint="1234567890"
    app:allowed_chars="1234567890"
    app:mask="+44(###)###-##-##"
    app:keep_hint="true" />

Where mask is the input mask you want and '#' is an editable position (will be replaced by a whitespace on screen).

You can optionally set the representation character (in case you don't want to use '#'):

<com.arefbhrn.maskededittext.MaskedEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    mask:mask="ccc.ccc.ccc-cc"
    mask:char_representation="c" />

You can also use the it programmatically:

MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)

// Setting the representation character to '$'
editText.setCharRepresentation('$');

// Get the representation character
editText.getCharRepresentation();

// Setting the mask
editText.setMask("##/##/####");

// Logging the mask
editText.getMask();

// Get typed text without mask chars
editText.getRawText();

// Keep hint showing
editText.setKeepHint(true);

Contact me

If you have a better idea or way on this project, please let me know, thanks :)

Email

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

maskededittext's People

Contributors

arefbhrn avatar

Watchers

James Cloos 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.