有没有办法限制 React-Native 中 TextInput 的长度? [英] Is there a way to limit the length of a TextInput in React-Native?
问题描述
我一直在努力使我的程序不允许您将超过一定数量的字符输入到 TextInput 组件中,类似于 maxLength 对输入的工作方式.我一直无法为 textInput 找到任何类似的 maxLength.有没有一种简单的方法可以为 < 设置最大字符数?TextInput/> 组件?
I've been trying to make it so that my program does not allow you to input more than a certain amount of characters into a TextInput component, similar to how maxLength works for input. I haven't been able to find anything similar maxLength for textInput. Is there an easy way to set a maximum number of characters for the < TextInput /> component?
推荐答案
在 TextInput 的 props 中,你可以设置 maxLength 属性.
In the props for TextInput you can set a maxLength attribute.
来自文档:
maxLength 数字
限制可以输入的最大字符数.使用它而不是在 JS 中实现逻辑以避免闪烁.@平台ios
Limits the maximum number of characters that can be entered. Use this instead of implementing the logic in JS to avoid flicker. @platform ios
这篇关于有没有办法限制 React-Native 中 TextInput 的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!