有没有办法在没有标点符号的情况下键入数字小键盘?
<TextInput keyboardType='numeric' ..... />
如果我使用secureTextEntry={true}
,它会获得我想要的正确键盘,但这些值会替换为*
。
答案 0 :(得分:2)
你试过number-pad
吗?在iOS上,number-pad
和numeric
都适合我。
答案 1 :(得分:0)
keyboardType = {“数字键盘”}在Android上有效。 注意:我使用的是来自react-native-elements的FormInput。
答案 2 :(得分:0)
我遇到了同样的问题。
我可以解决做这样的事情:
keyboardType={Device.isAndroid ? "numeric" : "number-pad"}
,然后从onChangeText
进行方法调用:
const cleanNumber = number.replace(/[^0-9]/g, "");
this.setState({
cleanNumber
});
它是TextInput的价值支柱
value={this.state.cleanNumber}
答案 3 :(得分:0)
未提供反应本机keyboardType
,可从键盘上删除标点符号。您需要使用带有replace方法的正则表达式从文本中删除标点符号并设置keyboardType = 'numeric'
。
正则表达式
/ [-#*;,.. <> {} [] \ /] / gi
示例代码
onTextChanged(value) {
// code to remove non-numeric characters from text
this.setState({ number: value.replace(/[- #*;,.<>\{\}\[\]\\\/]/gi, '') });
}
请检查小吃链接
答案 4 :(得分:0)
答案 5 :(得分:0)
就我而言,对于 Android,我防止使用 Miguel Cardenas 示例设置任何特殊字符。
这是我所做的:
const inputRef = useRef(null);
const setRefValue = v => {
const clean = v.replace(/[^0-9]/g, '');
inputRef.current.value = clean;
inputRef.current.setNativeProps({ text: clean });
}
};
<TextInput
ref={inputRef}
keyboardType={numeric}
onChangeText={setRefValue}
/>
每次输入 TextInput 时,常量 setRefValue
都会清除特殊字符。
答案 6 :(得分:-2)
(Platform.OS === 'ios') ? 'done' : 'next' — 好点
答案 7 :(得分:-3)