你的位置:首页 > Java教程

[Java教程]JS驗證兩位小數


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;