Flutter Textformfield:在TextFormField输入中需要一个特殊字符
我正在使用Flutter中的TextFormfield输入登记页面。
我想要的是,如果没有char'@'和'。然后它将被拒绝。
这是我希望的结果:
输入:name
errortext:“您应该输入有效的电子邮件地址”
响应:成功
,这是我的代码:
TextFormField(
keyboardType: TextInputType.emailAddress,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp("[a-z0-9@._-]")),
],
onChanged: (text) {
_onSearchChanged(text);
},
controller: emailController,
decoration: InputDecoration(
errorText:
isEmailInvalid ? "Email is already taken" : null,
hintText: 'Enter your email',
suffixIcon: isEmailvalid
? const Icon(
Icons.check,
color: Colors.green,
)
: const Icon(
Icons.check_circle,
color: Colors.transparent)
)),
I'm using TextFormField in Flutter to input email for register page.
What I want is if there's no char '@' and '.' then it will get rejected.
This is the result I hope for :
input : name
errorText : "You should enter valid email address"
input : [email protected]
response : success
And this is my code :
TextFormField(
keyboardType: TextInputType.emailAddress,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp("[a-z0-9@._-]")),
],
onChanged: (text) {
_onSearchChanged(text);
},
controller: emailController,
decoration: InputDecoration(
errorText:
isEmailInvalid ? "Email is already taken" : null,
hintText: 'Enter your email',
suffixIcon: isEmailvalid
? const Icon(
Icons.check,
color: Colors.green,
)
: const Icon(
Icons.check_circle,
color: Colors.transparent)
)),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用它来验证电子邮件,告诉我是否有任何问题
You can use it to validate email, tell me if have any problem
您需要将TextFieldForm包裹在表单中,并为其设置验证器。您可以参考此示例代码:
You need to wrap your TextFieldForm inside a Form and set the validator for it. You can refer to this example code: