代码:
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(text) => {
const newText = text.replace(/[^\d]+/, '');
this.setState({inputValue: newText})
}}
value={this.state.inputValue}
keyboardType='numeric'
/>
我希望用户只能输入数字,其他人将被替换。但实际上,没有任何影响。
ios> 10
“反应”:“16.3.1”,
“react-native”:“^ 0.55.3”,
我在你身边测试了你的样品并且效果很好:https://snack.expo.io/@sanjar/so52091526
您是否在构造函数中设置了状态的默认值?