如何限制“0”不應該放在text fieldFlutter中的第一個字符?下面是示例飛鏢代碼。
TextField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(
RegExp("[0-9\u0660-\u0669]")),
],
keyboardType: TextInputType.number,
focusNode: _nodeText1,
controller: mobileNumber,
decoration: InputDecoration.collapsed(
fillColor: TuxedoColor.whiteColor,
hintText: "5xxxxxxxx"),
),
uj5u.com熱心網友回復:
用這個 :
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(
RegExp(r'[0-9]'),
),
FilteringTextInputFormatter.deny(
RegExp(
r'^0 '), //users can't type 0 at 1st position
),
],
uj5u.com熱心網友回復:
試試下面的代碼使用FilteringTextInputFormatter.deny
TextField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp("[0-9\u0660-\u0669]")),
FilteringTextInputFormatter.deny(RegExp(r'^0 ')),
],
keyboardType: TextInputType.number,
decoration: InputDecoration.collapsed(hintText: "5xxxxxxxx"),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/450898.html
