jsp验证数字

来源:互联网 发布:淘宝阿迪达斯鞋子 编辑:程序博客网 时间:2024/05/22 07:52

function CheckNumber(obj)
    {
        //alert(obj.value);
        var allowQty = obj.value;       
        var numLength = obj.value.length;  
        if (allowQty!=""&&allowQty!=null)
        {           
            if (numLength == 1)
            {
                if (("0123456789").indexOf(allowQty) == -1)
                {
                    alert("Allow Qty must be numeral!");obj.value="";return false;
                }
            }
            else
            {
                var p=/^/d+/.?/d+$/;
                if (!p.test(allowQty))
                {
                    alert("Allow Qty must be numeral!");obj.value="";return false;
                }
            }

            if (parseFloat(allowQty) >= 1000000000000)
            {
                alert("Plan Allow Qty must be numeral,less than 1,000,000,000,000!");obj.value="";return false;
            }

            if ((allowQty).indexOf(".") != -1)
            {
                var tenIndex = (allowQty).indexOf(".");               
                if ((numLength -1 - tenIndex)> 6)
                {
                    alert("Allow Qty must be numeral,less than 6 number after '.'!");obj.value="";return false;
                }
            }

            if(allowQty==0)
            {
                alert("Allow Qty can not be zero!");obj.value="";return false;
            }

            var planQty = obj.parentElement.children[1].value;    
            if(planQty!=""&&planQty!=null)
            {
                var dif=allowQty-planQty;
                if(dif>0)
                {
                   alert('The Allow Qty can not be more than the Plan Qty!');obj.value="";return false;
                }
            }
        }
    }