// 正则匹配 金额 1,可以为负数 2, 最多允许小数点后两位
var pattern = new RegExp(/^([-+])?\d+(\.[0-9]{1,2})?$/),
str = '-1',
str1 = '-1.1',
str2 = '1.23';
console.log(pattern.test(str));
console.log(pattern.test(str1));
console.log(pattern.test(str2));
js正则匹配金额(允许负数)
最新推荐文章于 2023-11-15 11:44:26 发布