How to mask Text Input in React Native

In this React Native source code example, the source code below illustrate how to mask Text Input in React Native.

You can copy and adopt this source code example to your React Native project without reinventing the wheel.

import React, {Component} from 'react';
import { View,StyleSheet,TextInput,Text,Button} from 'react-native';
import { TextInputMask } from 'react-native-masked-text'; //You can check the package on github to see more masking options

export default class App extends Component {
  constructor(props) {
    this.state = { dt:'' ,amount:'10'};
    render() {
     return (
       <View style={styles.container}>
         <Text>Enter Date (YYYY/MM/DD)</Text>
             style={{width: '50%',height: 40,backgroundColor: 'white',justifyContent: 'center'}}
                format: 'YYYY/MM/DD'
              onChangeText={text => { this.setState({ dt: text}) }}

          <Text>Enter Amount</Text>
               style={{width: '50%',height: 40,backgroundColor: 'white',justifyContent: 'center'}}
                  precision: 0,
                  separator: '.',
                  delimiter: ',',
                  unit: '$',
                  suffixUnit: ''
                onChangeText={text => { this.setState({ amount: text  })}}  />

const styles = StyleSheet.create({
  myInput: {
    backgroundColor: 'rgb(232, 232, 232)',
    borderRadius: 30,
    height: 40,
    width: '90%'},

  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#8ee3ab',

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.


Add a Comment