正则表达式在飞镖中的双数 [英] Regex for double numbers in dart
本文介绍了正则表达式在飞镖中的双数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从我之前的问题开始,我试图只允许将双精度格式的数字输入到TextField中.我浏览了整个万维网,却没有找到用于飞镖的正则表达式.
As from my previous question I'm trying to allow only numbers in double format into a TextField. I have looked through the whole wide web and didn't find a Regex for dart.
TextFormField(
inputFormatters: [
WhitelistingTextInputFormatter(RegExp(r'\d*\.?\d+')) //<-- useless attempt to allow double digits only
])
推荐答案
您可以尝试:
WhitelistingTextInputFormatter(RegExp(r'(^\d*\.?\d*)'))
以下是此正则表达式的更严格版本.如果用户按除所需格式以外的任何无效字符,则该字段将被清除.
And the following is a stricter version of this regex. If the user press any invalid character other than the desired format the field will get cleared.
WhitelistingTextInputFormatter(RegExp(r'(^\d*\.?\d*)$'))
这篇关于正则表达式在飞镖中的双数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文