【发布时间】:2021-09-05 17:26:20
【问题描述】:
在输入文本字段中允许有效大小写并防止无效大小写
输入字段必须接受以下内容:
有效案例qw12@
qwe12qweryt@123
并且不接受以下内容:
大小写无效1a@@qwe11@qwer
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: javascript html jquery input-field
输入字段必须接受以下内容:
有效案例qw12@
qwe12qweryt@123
并且不接受以下内容:
大小写无效1a@@qwe11@qwer
【问题讨论】:
标签: javascript html jquery input-field
你可以这样做,让你的 textInput 成为一个受控组件
const [textInputValue, setTextInputValue] = useState('')
const onTextInputChange = (newText) => {
//Here you can manipulate the value of the textinput as you want
setTextInputValue(newText)
}
return (
<View style={styles.container}>
<TextInput style={styles.textInput} value={textInputValue} onChangeText={onTextInputChange} />
</View>
);
考虑到使用此解决方案,如果用户键入速度比 react-native 能够更新本机视图,您可能会遇到一些闪烁问题。
否则,您可以尝试在本地实现它,例如 here's TextInput 组件的自定义包装器示例,它允许将正则表达式传递给白名单允许的字符
【讨论】: