• Stars
    star
    465
  • Rank 94,287 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The custom mask for EditText. The solution for masked edit text input phone numbers, SSN, and so on for Android

Announcement: let's travel the world! or let's just be guests :)

MaskedEditText

Download Build Status

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

Announcement: let's travel the world! or let's just be guests :)

This project derives from toshikurauchi/MaskedEditText, but it's been adapted for gradle build system and has additional features:

  1. filter allowed chars
  2. filter denied chars
  3. user can use chars from mask in his input (in original version of this library user couldn't use digit '7' in the '+7(XXX)XXX-XX-XX' pattern).
  4. You can keep hints even when user started typing.

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

Enjoy!

Get it on Google Play


en_US

MaskedEditText is a simple Android EditText with customizable input mask support.

For instance, you need user specified his phone in format +7(XXX)XXX-XX-XX. You also know user should have the only possibility to write digits but minuses, brackets and "+7" should appear automatically.

Usage

Add this to your build.gradle :

compile 'ru.egslava:MaskedEditText:1.0.5'

Or download project and plug it in as a library.

Announcement: let's travel the world! or let's just be guests :)

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

  <br.com.sapereaude.maskedEditText.MaskedEditText
    android:id="@+id/phone_input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:typeface="monospace"
    mask:allowed_chars="1234567890"
    mask:mask="+7(###)###-##-##"
    android:hint="1234567890"
    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 '#'):

<br.com.sapereaude.maskedEditText.MaskedEditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    mask:mask="ccc.ccc.ccc-cc"
    mask:char_representation="c"
/>

Announcement: let's travel the world! or let's just be guests :)

You can also change the mask and the representation character programatically:

MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)
// Setting the representation character to '$'
editText.setCharRepresentation('$');
// Logging the representation character
Log.i("Representation character", editText.getCharRepresentation());
// Setting the mask
editText.setMask("##/##/####");
// Logging the mask
Log.i("Mask", editText.getMask());

To enable Enter softkey action (IME action):

<br.com.sapereaude.maskedEditText.MaskedEditText
    ...
    mask:enable_ime_action="true"
    ...
/>

Announcement: let's travel the world! or let's just be guests :)

Or programmatically:

MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)
editText.setImeActionEnabled(true);

ru_RU

MaskedEditText - это всего лишь EditText, но с возможностью задавать произвольную маску.

Например, нужно ввести телефон в формате +7(XXX)XXX-XX-XX. Причём можно ввести только цифры, а скобочки, дефисы и "+7" должны подставляться самостоятельно.

Использование

Вписать в build.gradle:

compile 'ru.egslava:MaskedEditText:1.0.5'

или скачать проект и подключить как библиотеку.

Добавить xmlns:mask="http://schemas.android.com/apk/res-auto" в корневой элемент файла разметки:

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

mask задаёт требуемую маску, символ '#' задаёт редактируемую позицию (и будет заменён на пробел на экране).

Если использовать '#' нельзя, то можно попробовать использовать другой символ:

<br.com.sapereaude.maskedEditText.MaskedEditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    mask:mask="ccc.ccc.ccc-cc"
    mask:char_representation="c"
/>

Кроме того, всё тоже самое можно сделать и программно:

MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)
// Setting the representation character to '$'
editText.setCharRepresentation('$');
// Logging the representation character
Log.i("Representation character", editText.getCharRepresentation());
// Setting the mask
editText.setMask("##/##/####");
// Logging the mask
Log.i("Mask", editText.getMask());

Чтобы включить обработку нажатия Enter (IME action):

<br.com.sapereaude.maskedEditText.MaskedEditText
    ...
    mask:enable_ime_action="true"
    ...
/>

Или программно:

MaskedEditText editText = (MaskedEditText) findViewById(R.id.my_edit_text)
editText.setImeActionEnabled(true);

More Repositories

1

BlurredImageView

Blurred ImageView for your android designes
Java
75
star
2

Example-Android-TextureView-OpenGL-Stable

Example of simple Android application uses TextureView with OpenGL ES 2. Written in Kotlin
Kotlin
20
star
3

android-nanovg-sample

The example of integration of nano-vg library to Android projects
C
17
star
4

freemind-todo

It generates "todo" list from your FreeMind mindmap
JavaScript
13
star
5

example-android-opengl-textureview-easy

A very simple example of using TextureView on Android with Kotlin
Kotlin
6
star
6

timeit-cpp

A C++ version of Python's timeit module
C++
6
star
7

example-Kotlin-Android-GLSurfaceView

How to use GLSurfaceView in your Android project? Example written in Kotlin
Kotlin
5
star
8

normal-mapping-demonstration

The demonstration of per-pixel lighting in 2d space using normal maps.
Java
4
star
9

russian_tajik_dictionary

Tajik<->Russian dictionary for Android platform
Java
4
star
10

ScalaMiniFTP

Minimalistic and easy-configurate FTP-server written on Scala
Scala
4
star
11

In-Width-search-JavaScript-demonstration

It is my first labour work for Artificial Intelligence. It resolves tags game.
JavaScript
3
star
12

healty-diet

Healthy diet plan generator for longevity. From your own ingredients, takes into account cals, fats, prots and carbs.
Python
2
star
13

blood-pressure-insights

You put the data, the app (Jupyter Notebook) gives you the insights
Jupyter Notebook
2
star
14

BridgeWS

WebSocket <-> Socket proxy server (bridge)
Java
1
star
15

psychology

This's application for my friend psychologist for social voting
Java
1
star
16

arena_shooter

A test task. Please, don't pay attention to this repository, but feel free to steal some code parts (CMake? :) )
C
1
star