繁体   English   中英

8 位数字的正则表达式,然后是 1 个点,之后只有 2 位数字

[英]Regex for 8 digits and after that 1 dot and after that only 2 digits

我需要一个正则表达式来接受八位数字,然后是一个点,之后只有两位数字用于金额字段。

目前我正在使用这么多代码......

valLowLTL(val) {
    const val1 = val.split('.');
    const amountLowLTL = this.addBillingForm.get('invoicingAmtLowLTL') as FormControl;
    const re = /,/gi;
    val1[0] = val1[0].replace(re, '');
    if (val1[0].length > 8) {
      val1[0] = val1[0].substring(0, 8);
    }
    amountLowLTL.setValue(val1[0]);
    if (val1.length > 1) {
      if (val1[1].length > 2) {
        val1[1] = val1[1].substring(0, 2);
      }
      const lowValLTL = val1[0].concat('.').concat(val1[1]);
      amountLowLTL.setValue(lowValLTL);
    }
}

我只需要一个简单的正则表达式来帮助我。

您可以使用正则表达式: ^\\d{8}[.]\\d{2}$

[\d]{8}\.[\d]{2}

或者

[0-9]{8}\.[0-9]{2}

https://regex101.com/r/SBAUc8/1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM