/** * * @param {Int,Float} value 数值 * @param {Int} effLen 有效长度 * @param {Int} deciLen 保留小数点 */ validateNumber (value, effLen, deciLen) { if (!value) { return { isValid: false, msg: null } } let intLen = effLen – deciLen – 1 // /(^[1-9][0-9]{0,12}(\.\d{1,2})?$)|(^[0-9]\.\d{1,2}?$)|(^[1-9][0-9]{0,12}$)/ let regk = ‘/(^[1-9][0-9]{0,’ + intLen + ‘}(\\.\\d{1,’ + deciLen + ‘})?$)|(^[0-9]\\.\\d{1,’ + deciLen + ‘}?$)|(^[1-9][0-9]{0,’ + intLen + ‘}$)/’ let reg = this.evil(regk) if (!reg.test(value + ”)) { return { isValid: false, msg: new Error( ‘最多输入 ‘ + (effLen – deciLen) + ‘ 位正整数, ‘ + deciLen + ‘ 位小数’ ) } } else { return true } },
转载于:https://www.cnblogs.com/gudun/p/9521923.html