【问题标题】:Want only one or|two digits number before the decimal point in textfield flutter. And User can't add more than three digits after the decimal point [closed]只希望文本字段中小数点前的一位或|两位数字颤动。并且用户不能在小数点后添加超过三位[关闭]
【发布时间】:2021-10-21 16:54:16
【问题描述】:

texfFormField 中的小数点前只有一位或两位数字颤动。并且用户不能在小数点后添加超过三位。

【问题讨论】:

    标签: flutter flutter-layout flutter-dependencies flutter-animation flutter-test


    【解决方案1】:

    你可以使用 RegExp 类

    final isValidNumber = RegExp(r'^([0-9]{2})*\.[0-9]{2}$');
    
    if (!isValidNumber .hasMatch(number))
        numbererror = "Please Enter Valid Name";
    else
       numbererror = "";
    

    【讨论】:

      【解决方案2】:

      如果用户输入的字符串称为value

      List<String> split = value.split('.');
      if (split.elementAt(0).length > 2 || split.elementAt(1).length > 3) print('Not valid'); 
      

      如果您需要更高级的东西:How to allow only 2 digits and 1 digit after the comma (.)?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-11
        • 2013-02-08
        • 1970-01-01
        • 2021-12-31
        • 1970-01-01
        • 2010-11-20
        • 1970-01-01
        相关资源
        最近更新 更多