import { validInputNumber } from "../../../utils/util.js"
// 分油码分配金额改变
bindKeyInput (e) {
this.setData({
amountInput: validInputNumber(e.detail.value)
})
}
utils/util.js
- // 输入框允许输入
- export const validInputNumber = (num) => {
- num === undefined && (num = '')
- if (/^(\d?)+(\.\d{0,2})?$/.test(num)) { //正则验证,充值金额小数点后不能大于两位数字
- return num
- } else {
- let str1 = num.replace(/[^\d^\.]+/g, '');
- let str2 = str1.split(".");
- let str3 = '';
- if (str2.length > 1) {
- str3 = str2[1].substring(0, str2[1].length > 2 ? 2 : str2[1].length);
- return str2[0] + (str2[1].length ? "." + str3 : "")
- } else {
- return str2[0]
- }
- }
- }
- module.exports = {
- validInputNumber
- }