javascript - 8位数字的正则表达式,之后是1个点,之后只有2位数字
问题描述
我需要一个正则表达式来接受八位数字,然后是一个点,之后只有两位数字用于金额字段。
目前我正在使用这么多代码......
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}$
推荐阅读
- java - 来自 RestTemplate 的 API 的响应需要传递给请求正文中的另一个。但它因 400 错误而失败
- javascript - 滑块中的第二项在执行时未显示在网页上
- flutter - 如何在颤动中滚动到 GridView 中的特定行?
- javascript - 当使用javascript或jQuery从填充的文本框中选择任何值而不单击提交按钮时如何提交表单
- java - 有没有办法在 Kotlin 的构造函数中声明 T ?
- c++ - xcodebuild 如何将 WARNING_CFLAGS 传递给 buildsettings
- git - Git - 检查是否在 git merge 中手动取消了某些文件
- javascript - 单击输入类型文本后如何修改下拉列表的缓存值
- javascript - VUE JS 防止路由器链接的事件传播
- java - 使用 sessionFactory 通过 HibernateOGM 连接到 MongoDB 失败