在Flutter中将正则表达式设置为电话号码格式

时间:2019-01-05 16:59:20

标签: flutter

我如何防止用户在TextFiled中插入点,逗号或空格。。用户需要设置11号(即07956432101)以允许他进入下一页。用Flutter工作 任何建议...

final TextEditingController x = new TextEditingController();

String p = "[\,\.\s\-]";

void Send(String str) => setState(() {
RegExp _regExp = new RegExp(p);
if (x.text.isEmpty || x.text.length < 11 || x.text == _regExp) {
name2 = "Invalid phone Number !!! ";
} else
{
Navigator.pushNamedAndRemoveUntil(
context, '/second', (Route<dynamic> route) => false);
}
});

child: new TextField(
textInputAction: TextInputAction.go , 
controller: x,
keyboardType: TextInputType.number,
maxLength: 11,
maxLengthEnforced: true,
decoration: new InputDecoration(
icon: Icon(Icons.phone),
hintText: "Phone number",
),
onChanged: NewVlaue,
onSubmitted: Send, 
),
),

0 个答案:

没有答案