货币金额
验证货币金额,只支持 正数、不支持校验 千分位分隔符。
语法
import { moneyReg } from 'warbler-js';const result = moneyReg(value);
参数
value(String) : 待验证字符串。
返回值
Boolean : 是否通过验证,true 通过验证, false 没有通过验证。
源码
const moneyReg = (value) => {const reg = /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/;return reg.test(value);};
例子
import { moneyReg } from 'warbler-js';const result1 = moneyReg('500')const result2 = moneyReg('-3')const result3 = moneyReg('3.99')const result4 = moneyReg('12,345,678.90')console.log(result1) // trueconsole.log(result2) // falseconsole.log(result3) // trueconsole.log(result4) // false
