js 正则表达式 验证小数点后几位

function IsFloatByBit (value, state, bit) {
            if (state == false) {
                var reg = new RegExp("^\\d+(\\.\\d{" + bit + "})*$", "ig");
                return reg.test(value);
            } else {
                var reg = new RegExp("^[-]?\\d+(\\.\\d{" + bit + "})*$", "ig");
                return reg.test(value);
            }
        }
posted @ 2017-06-30 09:26  帕丁顿熊  阅读(3408)  评论(0编辑  收藏  举报