I want convert number to * and add space after every 4 digits. ex: 12345678 -> 1234 5678 -> **** **** Now i just convert number to * but can't add space . ( when convert number to * , add space function not work ) Please help me!
import React, { Component } from 'react';
import { Text, TextInput, View } from 'react-native';
export default class PizzaTranslator extends Component {
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
<Text style={{padding: 10, fontSize: 42}}>
{this.state.text.replace(/(\(-?\d+(?:\.\d*){4})/g,'$1').replace(/(^\s+|\s+$)/,'') .slice(20).padStart(this.state.text.length, '*')}
</Text>
</View>
);
}
}
i expect input : 123456789123 output: **** **** ****