• Stars
    star
    1,217
  • Rank 38,518 (Top 0.8 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created about 8 years ago
  • Updated 12 months ago

Reviews

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

Repository Details

User input masking library repo.

Input Mask

Android Arsenal Awesome Actions iOS Version Telegram license

Input masks restrict data input and allow you to guide users to enter correct values.
Check out our wiki for quick start and further reading.

⚙️ Features

  • Apply formatting to your text fields, see examples
  • Filter out nonessential symbols (e.g. extract 0123456 from +1 (999) 012-34-56)
  • For international phone numbers
    • guess the country from the entered digits
    • apply corresponding value restrictions (e.g. a 🇺🇸US phone will have a format like +1 201 456-7890)
  • Apply number/currency formatting

💳 Examples

  • Phone numbers: +1 ([000]) [000] [00] [00]
  • Dates: [00]{.}[00]{.}[9900]
  • Serial numbers: [AA]-[00000099]
  • IPv4: [099]{.}[099]{.}[099]{.}[099]
  • Visa/MasterCard numbers: [0000] [0000] [0000] [0000]
  • UK IBAN: GB[00] [____] [0000] [0000] [0000] [00]

🛠️ Installation

Gradle

Make sure you've added Kotlin support to your project.

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.redmadrobot:input-mask-android:7.2.4'
    
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:$latest_version'
}

📢 Communication, Questions & Issues

Please take a closer look at our Known issues section before you incorporate our library into your project.

For your bugreports and feature requests please file new issues via GitHub.

Should you have any questions, please search for closed issues or ask questions at StackOverflow with the input-mask tag.

❗Known issues

InputMask vs. NoClassDefFoundError

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;

Receiving this error might mean you haven't configured Kotlin for your Java only project. Consider explicitly adding the following to the list of your project dependencies:

implementation 'org.jetbrains.kotlin:kotlin-stdlib:$latest_version'

— where latest_version is the current version of kotlin-stdlib.

InputMask vs. android:inputType and IndexOutOfBoundsException

Be careful when specifying field's android:inputType. The library uses native Editable variable received on afterTextChange event in order to replace text efficiently. Because of that, field's inputType is actually considered when the library is trying to mutate the text.

For instance, having a field with android:inputType="numeric", you cannot put spaces and dashes into the mentioned Editable variable by default. Doing so will cause an out of range exception when the MaskedTextChangedListener will try to reposition the cursor.

Still, you may use a workaround by putting the android:digits value beside your android:inputType; there, you should specify all the acceptable symbols:

<EditText
    android:inputType="number"
    android:digits="0123456789 -."
    ... />

— such that, you'll have the SDK satisfied.

Alternatively, if you are using a programmatic approach without XML files, you may consider configuring a KeyListener like this:

editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789 -.")); // modify character set for your case, e.g. add "+()"

InputMask vs. autocorrection & prediction

(presumably fixed by PR50)

Symptoms:

  • You've got a wildcard template like [________], allowing user to write any kind of symbols;
  • Cursor jumps to the beginning of the line or to some random position while user input.

In this case text autocorrection & prediction might be a root cause of your problem, as it behaves somewhat weirdly in case when field listener tries to change the text during user input.

If so, consider disabling text suggestions by using corresponding input type:

<EditText
    ...
    android:inputType="textNoSuggestions" />

Additionally be aware that some of the third-party keyboards ignore textNoSuggestions setting; the recommendation is to use an extra workaround by setting the inputType to textVisiblePassword.

InputMask vs. android:textAllCaps

Kudos to Weiyi Li for reporting this issue

Please be advised that android:textAllCaps is not meant to work with EditText instances:

This setting will be ignored if this field is editable or selectable.

Enabling this setting on editable and/or selectable fields leads to weird and unpredictable behaviour and sometimes even crashes. Instead, consider using android:inputType="textCapCharacters" or workaround by adding an InputFilter:

final InputFilter[] filters = { new InputFilter.AllCaps() };
editText.setFilters(filters);

Bare in mind, you might have to befriend this solution with your existing android:digits property in case your text field accepts both digits and letters.

🙏 Special thanks

These folks rock:

♻️ License

The library is distributed under the MIT LICENSE.

More Repositories

1

figma-export

Command line utility to export colors, typography, icons and images from Figma to Xcode / Android Studio project
Swift
733
star
2

input-mask-ios

User input masking library repo.
Swift
578
star
3

Chronos

Android library that handles asynchronous jobs.
Java
133
star
4

state-delegator

Collection of classes that helps you to manage a screen state.
Kotlin
132
star
5

gradle-version-catalogs

Version catalogs used in red_mad_robot Android team
Kotlin
93
star
6

style-guides

red_mad_robot Style Guides
89
star
7

PINkman

PINkman is a library to help implementing an authentication by a PIN code in a secure manner. The library derives hash from the user's PIN using Argon2 function and stores it in an encrypted file. The file is encrypted with the AES-256 algorithm in the GCM mode and keys are stored in the AndroidKeystore.
Kotlin
85
star
8

DAO

Swift
74
star
9

flipper

Flipper is a simple and useful tool to deal with feature toggles
Kotlin
71
star
10

RMRColorTools-iOS

Objective-C
67
star
11

catbird

Mock server for UI tests
Swift
50
star
12

edge-to-edge-decorator

Edge to edge decorator - is a utility class that is responsible for coloring the statusBar and navigationBar to maintain edge to edge (e2e) mode.
Kotlin
48
star
13

apexy-ios

The library for organizing a network layer in your awesome project.
Swift
44
star
14

gradle-infrastructure

Set of small plugins to reduce boilerplate in Gradle build scripts.
Kotlin
43
star
15

NeumorphicWallet

💳 Neumorphic Wallet app concept in SwiftUI
Swift
43
star
16

PrioritizedTabBar

📱 Native iOS TabBar with prioritized layout
Swift
41
star
17

gears-android

Small though useful libraries to build Android apps
Kotlin
29
star
18

omega-bank-ios

The Bank you really need.
Swift
28
star
19

Alarm-Clock

⏰ Alarm Clock / Proof of concept for our Colored Alarm Clock Interface shot @ Dribbble
Swift
27
star
20

figmiro-plugin

Figma Integration with Miro (Plugin)
TypeScript
26
star
21

perspective-animation-ios

Example of perspective photo animation from camera
Swift
25
star
22

mapmemory

Simple in-memory cache conception built on Map.
Kotlin
22
star
23

acronym-avatar

Library to show avatars with acronyms.
Kotlin
18
star
24

ACSlider

🎚 A slider displaying selected value
Swift
16
star
25

fastlane-plugin-jira_release_notes

Fastlane Plugin for Jira Release Notes
Ruby
15
star
26

synopsis

Swift source code scanner.
Swift
13
star
27

itemsadapter

The simple adapter to render static data in RecyclerView
Kotlin
12
star
28

golden-key

Security framework compatible with CryptoKit
Swift
12
star
29

VolumeButtons

VolumeButtons provides interface for handle clicks on hardware volume buttons on iOS devices
Swift
11
star
30

android-mad-showcase

Welcome to Modern Android Development (MAD) Showcase, the Android application following modern practices: Kotlin, Coroutines, Flow, Compose, GraphQL etc
Kotlin
11
star
31

navidux

Swift
10
star
32

DAO-generator

Swift
10
star
33

AndroidStudioTemplates

Templates for android studio
FreeMarker
9
star
34

android-docker-images

Docker images used in red_mad_robot Android team
Shell
7
star
35

fastlane-plugin-gmail

Fastlane Plugin for Gmail
Ruby
7
star
36

rmr_django

Template Django project
Python
7
star
37

http-transport

Synchronous HTTP transport library.
Swift
7
star
38

debug-panel-android

Library for easy application debugging
Kotlin
6
star
39

figmiro-server

This is proxy server for Figmiro plugin that works with Miro's REST API
TypeScript
6
star
40

FitnessAppWithDynamicIsland

Demo app designed to demostrate the capabilities of the new Apple Dynamic Island.
Swift
6
star
41

autograph

Swift source code generation kit.
Swift
5
star
42

frontend-robopractice-test-task

HTML
5
star
43

techradar-android

RMR Technology Radar
Kotlin
4
star
44

use-dropdown

HTML
4
star
45

FitnessDynamicIsland

Swift
4
star
46

service-autograph

Service generation utility.
Swift
4
star
47

fastlane-plugin-imessage

Ruby
4
star
48

model-compiler

Swift
4
star
49

danger-jira_issue_links

Danger plugin
Ruby
4
star
50

core-parser-generator

Swift
3
star
51

core-parser

Swift
3
star
52

parser-autograph

Object parser generation utility.
Swift
3
star
53

Konfeature

Kotlin library for working with feature remote configuration
Kotlin
2
star
54

TextValue

TextValue is an abstraction over Android text
Kotlin
2
star
55

floating-text-input

Swift
2
star
56

opensource

Redmadrobot opensource
Ruby
2
star
57

homebrew-formulae

Redmadrobot Homebrew tap
Ruby
2
star
58

rmr-docker

Shell
1
star
59

service-generator

Swift
1
star
60

Toaster

Swift
1
star