• Stars
    star
    414
  • Rank 104,550 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

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

Repository Details

๐ŸŽญ A React Native and Expo library to mask text and inputs

react-native-mask-text

This is a library to mask Text and Input components in React Native and Expo (Android, iOS and Web).

Motivation

This package was created based on other libraries of React Native text mask, with the goal of meeting the need of having a package to be used with all React Native contexts (multi-platform concept) and also be maintained currently. You can read this blog post on Substack to see more information about the creation to the current moment of this package.

Install

yarn add react-native-mask-text

Custom Mask

Pattern used in masked components:

  • 9 - accept digit.
  • A - accept alpha.
  • S - accept alphanumeric.

Ex: AAA-9999

Usage MaskedTextInput (custom)

Component similar with <TextInput /> but with custom mask option.

import { StyleSheet } from "react-native";
import { MaskedTextInput } from "react-native-mask-text";

//...

<MaskedTextInput
  mask="AAA-9999"
  onChangeText={(text, rawText) => {
    console.log(text);
    console.log(rawText);
  }}
  style={styles.input}
/>;

//...

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
  },
});

Usage MaskedText (custom)

Component similar with <Text /> but with custom mask option.

import { MaskedText } from "react-native-mask-text";

//...

<MaskedText mask="99/99/9999">30081990</MaskedText>;

Date Mask

These options only are used if you use prop type="date" in your component:

Option Type Mandatory Default Value Description
dateFormat string No yyyy/mm/dd Date Format

Usage MaskedTextInput (date)

Component similar with <TextInput /> but with date mask option.

import { StyleSheet } from "react-native";
import { MaskedTextInput } from "react-native-mask-text";

//...

<MaskedTextInput
  type="date"
  options={{
    dateFormat: 'YYYY/DD/MM',
  }}
  onChangeText={(text, rawText) => {
    console.log(text);
    console.log(rawText);
  }}
  style={styles.input}
  keyboardType="numeric"
/>

//...

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
  },
});

Time Mask

These options only are used if you use prop type="time" in your component:

Option Type Mandatory Default Value Description
timeFormat string No HH:mm:ss Time Format

Usage MaskedTextInput (time)

Component similar with <TextInput /> but with time mask option.

import { StyleSheet } from "react-native";
import { MaskedTextInput } from "react-native-mask-text";

//...

<MaskedTextInput
  type="time"
  options={{
    timeFormat: 'HH:mm:ss', // or 'HH:mm'
  }}
  onChangeText={(text, rawText) => {
    setMaskedValue(text)
    setUnmaskedValue(rawText)
  }}
  style={styles.input}
  keyboardType="numeric"
/>

//...

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
  },
});

Currency Mask

These options only are used if you use prop type="currency" in your component:

Option Type Mandatory Default Value Description
prefix string No null String to prepend
decimalSeparator string No null Separation for decimals
groupSeparator string No null Grouping separator of the integer part
precision number No 0 Precision for fraction part (cents)
groupSize number No 3 Primary grouping size of the integer part
secondaryGroupSize number No null Secondary grouping size of the integer part
fractionGroupSeparator string No null Grouping separator of the fraction part
fractionGroupSize number No null Grouping size of the fraction part
suffix string No null String to append

Usage MaskedTextInput (currency)

Component similar with <TextInput /> but with currency mask option.

import { StyleSheet } from "react-native";
import { MaskedTextInput } from "react-native-mask-text";

//...

<MaskedTextInput
  type="currency"
  options={{
    prefix: '$',
    decimalSeparator: '.',
    groupSeparator: ',',
    precision: 2
  }}
  onChangeText={(text, rawText) => {
    console.log(text);
    console.log(rawText);
  }}
  style={styles.input}
  keyboardType="numeric"
/>

//...

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
  },
});

Usage MaskedText (currency)

Component similar with <Text /> but with currency mask option.

import { MaskedText } from "react-native-mask-text";

//...

<MaskedText
  type="currency"
  options={{
    prefix: '$',
    decimalSeparator: '.',
    groupSeparator: ',',
    precision: 2
  }}
>
  5999
</MaskedText>;

Usage mask function

Function used to mask text.

import { mask } from "react-native-mask-text";

const code = mask("ABC1234","AAA-9999") // return ABC-1234

Usage unMask function

Function used to remove text mask.

import { unMask } from "react-native-mask-text";

const code = unMask("ABC-1234") // return ABC1234

Example

You can see an example app with Expo CLI here.

You can see a SignUp example on Expo Snack working with iOS, Mobile, and Web here.

Contributing

See Contributing.md

License

The app's source code is made available under the MIT license. Some of the dependencies are licensed differently, with the BSD license, for example.

Contact

Akinn Rosa - Github - [email protected]

More Repositories

1

ar-nft

๐Ÿ‘พ A React Native app to visualize your NFTs in AR
Java
82
star
2

expo-stack

๐ŸŽฎ๐Ÿงฑ Stack game clone made in Expo (iOS, Android, Web), Three.js, React Native
TypeScript
72
star
3

tse2022

Vote Counting Brazilian Elections 2022
TypeScript
40
star
4

rn-mirror-lists

๐Ÿชž Mirror scroll lists for React Native
TypeScript
39
star
5

github-stars

โœจ Fullstack monorepo web app to add tags on your starred repositories
TypeScript
32
star
6

amora

๐Ÿซ Amora is an app to help establishments to retain customers made with React Native
TypeScript
24
star
7

frogchain

๐Ÿธ ๐Ÿ’œ Crypto Wallet made with React Native
TypeScript
21
star
8

awesome-native-modules

๐ŸŒ‰ Some React Native bridges in one app
Java
21
star
9

crypto-colors

๐ŸŽจ CryptoColors NFT Collection
JavaScript
12
star
10

talk-rn-architecture-21

JavaScript
12
star
11

web3-playground-app

React Native app with Web3 Integration without boilerplates
Java
10
star
12

talk-open-source

Talk about Open Source
JavaScript
5
star
13

tiktok

tiktok ui clone
JavaScript
5
star
14

bytebank

๐Ÿฆ bytebank mobile app with flutter
Dart
3
star
15

fort-status

๐Ÿ”จ Mobile/Web app to find your Epic Games user information made with Expo, React Native, Redux
TypeScript
3
star
16

akinncar.github.io

๐Ÿก my personal website developed with gatsby
HTML
3
star
17

expo-star-wars

๐ŸŒ ๐Ÿš€ star wars informative app made in expo (ios, android), react native
TypeScript
3
star
18

lyrictube

๐ŸŽต google chrome extension to apply lyrics for youtube musics
JavaScript
3
star
19

aurum-app

mobile app developed with react native
JavaScript
2
star
20

contacts

๐Ÿ‘ฅ contacts app for ios
Objective-C
2
star
21

compress

node script to compress/optimize png images
JavaScript
2
star
22

poc-rn-webpack

Using Re.Pack to bundle a React Native app with Webpack
JavaScript
2
star
23

githuber

:octocat: github users finder app in react native
JavaScript
2
star
24

java-shitcoin

0xB37a9BF6F4beDc630E1a662347d56FC404A557B1
Solidity
2
star
25

mobile-covid19

JavaScript
2
star
26

gasolina-da-hora

site para mostrar o preรงos dos postos de gasolina das cidades
PHP
2
star
27

CameraApp

react native app to integrate camera native api
Java
2
star
28

acorde-no-ponto

Android app to wake up the user on arriving at bus destiny
Java
2
star
29

origamid-advanced-css

Advanced CSS Position Module from Origamid
CSS
2
star
30

react-native-jsi-poc

Java
2
star
31

garden

JavaScript
2
star
32

markitos-bot

๐Ÿค– markitos bot for discord with discord.js
JavaScript
1
star
33

doces-da-madra

๐Ÿฉ e-commerce to sell candies with symfony framework (term paper cedup technical course 2019)
PHP
1
star
34

business-name-generator

๐Ÿค– Generate business names with ChatGPT3 API
CSS
1
star
35

bricks

๐ŸŽฎ Bricks 2D game made with Unity
C#
1
star
36

FantomChess

A NFT collection of 500 random generated Chess games
JavaScript
1
star
37

context-api-boilerplate

context api boilerplate
JavaScript
1
star
38

todo-react-learning-path

Todo list made following https://gist.github.com/akinncar/657062dd3995fd1259a7b56e51bb13a5
JavaScript
1
star