MCPcopy Index your code
hub / github.com/IvanIhnatsiuk/react-native-advanced-input-mask

github.com/IvanIhnatsiuk/react-native-advanced-input-mask @v1.4.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.4.6 ↗ · + Follow
213 symbols 374 edges 94 files 4 documented · 2% 2 cross-repo links updated 4mo agov1.4.6 · 2025-10-06★ 24017 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

React Native Advanced Input Mask

Overview

react-native-advanced-input-mask is a React Native package that provides flexible input masking functionality for mobile applications. It allows you to format input fields dynamically as users type, ensuring that data is entered in a consistent and valid format. This package wraps the input-mask-android library for Android and its equivalent for iOS, offering a cross-platform solution.

Input masking can be used to format text fields for phone numbers, dates, credit card numbers, social security numbers, and other input types that require specific formatting.

Features

  • ✨ Ensures smooth, flicker-free text formatting in a real time.
  • 🧬 Supports multiple mask types and formats.
  • ⚡ Instantly applies the correct format as users type, without delays.
  • 🚀 Cross-platform support for iOS, Android and web.
  • 🛠️ Easy integration with existing React Native components.

Install the package using npm or yarn:

npm install react-native-advanced-input-mask
# or
yarn add react-native-advanced-input-mask

Usage

Import react-native-advanced-input-mask in your component to apply masking to input fields.

Basic Example

import React, { useState, useCallback } from "react";
import { TextInput, View } from "react-native";
import { MaskedTextInput } from "react-native-advanced-input-mask";

const ExampleComponent = () => {
  const [phoneNumber, setPhoneNumber] = useState("");

  const onChangeText = useCallback((formatted, extracted) => {
    setPhoneNumber(formatted);
  }, []);

  return (
    <MaskedTextInput
      autocomplete={false}
      mask="+1 ([000]) [000]-[0000]"
      value={phoneNumber}
      onChangeText={onChangeText}
      keyboardType="numeric"
    />
  );
};

export default ExampleComponent;

UK IBAN:

import React, { useState, useCallback } from "react";
import { TextInput, View } from "react-native";
import { MaskedTextInput } from "react-native-advanced-input-mask";

const ExampleComponent = () => {
  const [IBAN, setIBAN] = useState("");

  const onChangeText = useCallback((formatted, extracted) => {
    setIBAN(formatted);
  }, []);

  return (
    <MaskedTextInput
      autocomplete={false}
      mask="GB[00] [____] [0000] [0000] [0000] [00]"
      value={IBAN}
      onChangeText={onChangeText}
    />
  );
};

export default ExampleComponent;

Dates:

import React, { useState, useCallback } from "react";
import { TextInput, View } from "react-native";
import { MaskedTextInput } from "react-native-advanced-input-mask";

const ExampleComponent = () => {
  const [date, setDate] = useState("");

  const onChangeText = useCallback((formatted, extracted) => {
    setDate(formatted);
  }, []);

  return (
    <MaskedTextInput
      autocomplete={false}
      mask="[00]{.}[00]{.}[9900]"
      value={date}
      onChangeText={onChangeText}
    />
  );
};

export default ExampleComponent;

Detailed Mask Explanation

The mask pattern defines how user input is processed and displayed. The characters below are used for defining patterns:

  • [0]: mandatory digit. For instance, [000] will allow entering three digits: 123.
  • [9]: optional digit.For instance, [00099] will allow entering up to five digits, but at least three.
  • [A]: mandatory letter. For instance, [AAA] will allow entering three letters: ABC.
  • [a]: optional letter. [АААааа] will allow entering from three to six letters.
  • [_]: mandatory symbol (digit or letter).
  • [-]: optional symbol (digit or letter).
  • […]: ellipsis. Allows to enter endless count of symbols.

Advanced Usage

For applications requiring conditional or more complex formatting, this package provides additional configuration options.

Pipeline

When the user enters text, we remove all characters that aren't included in the <code>allowedKeys</code> property (if defined). Then we validate the input against the provided <code>validationRegex</code>. If the validation passes, we apply a mask; otherwise, we ignore the current change.

MaskedTextInput Component - Props

Prop Type Description
mask string The mask format to be applied to the text input, defining the pattern for formatting. Example: "[0000] [0000] [0000] [0000]".
customNotations Notation[] Array of custom notations for the mask format. Each notation object includes: character, characterSet, and isOptional.
allowedKeys string A string specifying the characters that are permitted for input.
validationRegex regex string A validation regex that runs before applying the mask.
onChangeText (formatted: string, extracted: string, tailPlaceholder: string, complete: boolean) => void Callback function triggered on text change. Receives formattedValue (with mask), extractedValue (raw input) tailPlaceholder (tail placeholder whish is calculated by entered value) and complete(flag shows if the extracted value contains all the mandatory characters).
onTailPlaceholderChange (tailPlaceholder: string) => void Callback function called when the tail placeholder changes, receiving the updated tailPlaceholder value.
affinityFormat string[] Array of strings for affinity format, used to determine the best mask format based on the input.
autocomplete boolean Autocompletion allows predictive insertion of constant characters. Default is true
autoSkip boolean Automatic character skipping works as an "anti-autocompletion", erasing the constant characters (see constant blocks and separators) at the end of the line when hitting backspace. Default is false.
isRTL boolean Enables right-to-left (RTL) text direction for the text input. Default is false.
affinityCalculationStrategy AFFINITY_CALCULATION_STRATEGY Defines the strategy for affinity calculation, determining how the best mask format is selected based on input.
customTransformation CustomTransformation Custom transformation applied to the text input to define how the input text should be transformed.
defaultValue string The default value for the input field.
value string Current value of the input field, allowing controlled input behavior.
allowSuggestions boolean (iOS only) Enables or disables input suggestions on iOS. Default is false.
autocompleteOnFocus boolean Enables autocomplete when the text input is focused.
placeholder string Placeholder text displayed in the input.
keyboardType string Sets the keyboard type. Useful for numeric masks with keyboardType="numeric".
autoFocus boolean If true, focuses the input on component load. Default is false.

Cookbook

Cookbook is a community-driven handbook with complete solutions for common problems.
Text formatting problems, of course.

Feel free to suggest your own recipes or correct the existing ones.

Chapters

Credit cards

MM/YY: [00]{/}[00]
CVV: [000]

American Express

[0000] [000000] [00000]
3[000] [000000] [00000]

Diners Club International

[0000] [000000] [0000]
3[000] [000000] [0000]

Discover

[0000] [0000] [0000] [0000]
6[000] [0000] [0000] [0000]

MasterCard

[0000] [0000] [0000] [0000]
5[000] [0000] [0000] [0000]

Visa

[0000] [0000] [0000] [0000]
4[000] [0000] [0000] [0000]

Amount inputs

[0999990].[09]

[!NOTE] To forbid entering not allowed characters, use allowedKeys prop. For example allowedKeys="0123456789,.".

Dates

Affine formats:

[00]{/}[00]{/}[00]
[00]{/}[00]{/}[0000]
[00]{.}[00]{.}[00]
[00]{.}[00]{.}[0000]

IBAN, International Bank Account Number

Extension points exported contracts — how you extend this code

CaretGravity (Interface)
(no doc)
package/src/web/model/types.ts
RootParamList (Interface)
(no doc)
apps/example/src/navigation/Root/types.ts
NativeProps (Interface)
(no doc)
package/src/native/specs/AdvancedTextInputMaskDecoratorViewNativeComponent.ts
NativeCommands (Interface)
(no doc)
package/src/native/specs/AdvancedTextInputMaskDecoratorViewNativeComponent.ts

Core symbols most depended-on inside this repo

push
called by 12
package/src/web/helper/AutocompletionStack.ts
apply
called by 11
package/src/web/helper/Mask.ts
setText
called by 7
package/src/web/AdvancedTextInputMaskListener.ts
get
called by 6
package/android/src/main/java/com/maskedtextinput/transformation/CustomTransformationMethod.kt
setText
called by 4
package/android/src/main/java/com/maskedtextinput/views/AdvancedTextInputMaskDecoratorView.kt
getOrCreate
called by 3
package/src/web/helper/Mask.ts
insertionAffectsCaret
called by 3
package/src/web/helper/CaretStringIterator.ts
next
called by 3
package/src/web/helper/CaretStringIterator.ts

Shape

Method 132
Class 50
Function 23
Enum 4
Interface 4

Languages

TypeScript54%
Kotlin43%
C++3%

Modules by API surface

package/android/src/main/java/com/maskedtextinput/views/AdvancedTextInputMaskDecoratorView.kt19 symbols
package/android/src/main/java/com/maskedtextinput/managers/AdvancedTextInputMaskDecoratorViewManager.kt19 symbols
package/android/src/oldarch/java/com/maskedtextinput/AdvancedTextInputMaskDecoratorViewManagerSpec.kt17 symbols
package/src/web/helper/Mask.ts14 symbols
package/src/web/AdvancedTextInputMaskListener.ts11 symbols
package/src/web/helper/Compiler.ts8 symbols
package/src/web/helper/RTLMask.ts7 symbols
package/src/web/helper/FormatSanitizer.ts7 symbols
package/src/web/model/state/ValueState.ts6 symbols
package/android/src/main/java/com/maskedtextinput/transformation/CustomTransformationMethod.kt6 symbols
package/android/src/main/java/com/maskedtextinput/listeners/ReactMaskedTextChangeListener.kt6 symbols
package/src/web/helper/CaretStringIterator.ts5 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add react-native-advanced-input-mask \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page