validation - 当 otp 字段在颤振中为空时,如何向 otp 文件添加验证
问题描述
在这里我遇到了一些问题。如何向纯文本字段或用于 OTP 输入的任何字段添加验证。如果有人有另一个 OTP 输入字段,请告诉我。希望你能理解。请帮我。
_onAlertotp(context) {
Alert(
context: context,
title: "OTP expires in: MM:SS (Counter",
desc:
"We have Texted and/or Emailed OTP (One Time Pin) to your registered cell phone and/ or email account. Please check and enter OTP below to activate your TUDO account",
content: Column(
children: <Widget>[
Form(
autovalidate: true,
child: PinField(
padding: EdgeInsets.all(16.0),
length: 6,
gap: 6.0,
onSubmitted: Validators().otpValidate,
keyboardType: TextInputType.numberWithOptions(signed: true),
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly]),
)
],
),
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
child: Text(
"Resend OTP",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
DialogButton(
onPressed: () {
_onAlertrunningbusiness(context);
},
child: Text(
"Enter Otp",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
解决方案
为了验证一个空字符串,您只需要检查它的值是否等于“”。
您可以使用 getter 函数isEmpty()
来检查 String 是否为空。
解决方案代码:
validator: (String value) {
if (value.isEmpty) {
return "Please enter phone number";
} else if (value.length != 10) {
return "Please enter valid Phone number";
} else {
return null;
}
},
推荐阅读
- node.js - 如何存储 SSE 连接?
- r - 如何在R中使用ggplot2垂直堆叠重叠点
- java - 来自数据库的 Anylogic 配电网络连接
- data-structures - XBee 协调器数据包接收
- reactjs - 无法在 React 中使用 openstreetmap 进行 D3 缩放?
- excel - Parse MM/DD from MM/DD/YYYY HH:MM string Excel
- reactjs - 如何构造 ReactJS 组件文件夹?
- html - How to replace html tags but keep the text in between?
- javascript - 如何将图标放置在文本的右侧
- c# - 解决警告 CS1998 时如何处理异常:此异步方法缺少“等待”运算符