简体   繁体   English

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

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

I need a regular expression for accepting eight digits and after that one dot and after that only two digits for amount fields.我需要一个正则表达式来接受八位数字,然后是一个点,之后只有两位数字用于金额字段。

Currently I'm using this much of code...目前我正在使用这么多代码......

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);
    }
}

I just need an simple regular expression which helps me out.我只需要一个简单的正则表达式来帮助我。

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

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

or或者

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

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

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

相关问题 正则表达式仅在美元符号后抓住数字 - Regex to grab only the digits after a dollar sign 忽略 '.' 之后的数字正则表达式 - ignore digits after '.' regex 前面有6位数的正则表达式和小数点后面的2位数 - regex for 6 digits before and 2 digits after decimal JavaScript; 三位数后如何设置点? - JavaScript; How to set dot after three digits? 在点后四舍五入到两位有效数字(javascript) - Rounding to two significant digits after the dot (javascript) 计算点后最多两位数的百分比 - Calculate percentage with up to two digits after the dot JavaScript 中的正则表达式允许最多 10 位数字,数字之间只有一个下划线,并防止在前 5 位数字后输入下划线 - Regex in JavaScript which allow maximum 10 digits, only one underscore in between the digits and prevent entering underscore after the first 5 digits Javascript正则表达式最多只能匹配11位数字,一个逗号和2位数字 - Javascript regex to match only up to 11 digits, one comma, and 2 digits after it JavaScript的; 四舍五入,将点更改为逗号,并在三位数后设置点 - JavaScript; Round, change dot to comma, and set dot after three digits 正则表达式仅验证 0-9 的数字,最多 8 位数字直到一个点,最多只有两位小数 - Regex to validate only digits from 0-9, maximum of 8 digits till a dot and only two decimals as maximum
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM