Skip to content

The custom masks for EditText. The solution for input phone numbers, SSN, and so on for Android

License

Notifications You must be signed in to change notification settings

DevenLu/edittext-mask

 
 

Repository files navigation

Don't click on meSorry everyone :-) My friend is looking for a remote job/freelance. So if you can recommend her some positions or just share this info - I would like to say you the big thanks.

She does responsive web layouts with SASS/Compass/JQuery/animate.css and can scaffold your the next design on bootstrap very fast in a very accurate manner.

portfolio

Under videos you can see project descriptions, time to complete, sources on github and all necessary info.

annelia1991@gmail.com skype: annelia_55

MaskedEditText

Download Build Status

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

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

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

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"
/>

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());

ru_RU

MarkedEditText - это всего лишь 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());

About

The custom masks for EditText. The solution for input phone numbers, SSN, and so on for Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%