JS验证两位小數

| 阅读数:--次| 作者:js,javascript
摘要:function SizeCheck(Textdiv) { var fg = true; str = $("#" + Textdiv).val(); var re = /^0?(\.\d{1,2})?$|^[1-9][0-9]{0,3}(\.\d{1,2})?$/; if (str == "") {...

function SizeCheck(Textdiv) {
                var fg = true;
                str = $("#" + Textdiv).val();
                var re = /^0?(\.\d{1,2})?$|^[1-9][0-9]{0,3}(\.\d{1,2})?$/;
                if (str == "") {
                    //alert("不能加空的");
                    fg = false;
                }
                else {
                    if (parseFloat(str).toFixed(2) > 1000.00 || parseFloat(str).toFixed(2) < 0.00) {                        fg = false;
                    }
                    else if (!re.test(str)) {
                                               fg = false;
                    }
                }
                return fg;

返回顶部
学到老代码浏览 关闭浏览