仅允许小写且无空格输入文本字段颤动 [英] Allow Only lowercase with no space Input Textfield Flutter
本文介绍了仅允许小写且无空格输入文本字段颤动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在制作一个聊天应用程序,我希望用户提交的用户名不应该是大写的并且有空间,我可以接受该名称并稍后在onChanged功能中更改它,但我也希望用户知道它
推荐答案
Ffltter的TextField
或TextFormField
具有名为inputFormatters
的属性,该属性采用TextInputFormatter
的列表。
适用于您的案例的TextInputFormatters
示例。
FilteringTextInputFormatter.allow(RegExp("[a-z]"))
TextField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp("[a-z]")),
],
)
您可以在这里看到TextInputFormatters
接口文档:Reference
(颤动1.20之前):
WhitelistingTextInputFormatter(RegExp("[a-z]")),
TextField(
inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp("[a-z]")),
],
)
不清楚可以参考:Reference 2、Reference 3。
另请查看此SOF问题:Reference 4
这篇关于仅允许小写且无空格输入文本字段颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文