我想将数字转换为 * 并在每 4 位数字后添加空格。例如:12345678 -> 1234 5678 -> **** **** 现在我只是将数字转换为 * 但不能添加空格。(将数字转换为 * 时,添加空格功能不起作用)请帮帮我!
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>
);
}
}
我期望输入:123456789123 输出:**** **** ****
慕工程0101907
慕姐8265434
相关分类