gpt4 book ai didi

react-native - Textinput 最小长度 React native

转载 作者:行者123 更新时间:2023-12-05 02:13:40 25 4
gpt4 key购买 nike

有没有办法将文本输入限制在最小长度和最大长度之间。假设我想将文本输入长度限制在 5 到 15 之间,我该怎么做?

最佳答案

考虑在您的组件中添加以下代码:

<TextInput onTextChange={this.onTextChange} maxLength={15} ... />
<Button onPress={this.onPress} ... >Submit</Button>

onTextChange = text => {
this.setState({text : text});
}

onPress = () => {
const {text} = this.state;

if(text.length < 5) {
console.log('Your text is less than what is required.');
}
}

关于react-native - Textinput 最小长度 React native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54761560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com