检验金额合法性, 只能是正数 或小数(常用js总结)

//检验金额合法性 只能是正数 或小数        
    function checkMoney(fileds){        
            $(fileds).keyup(function () {
                var reg = $(this).val().match(/\d+\.?\d{0,2}/);
                var txt = '';
                if (reg != null) {
                    txt = reg[0];
                }
                $(this).val(txt);
            }).change(function () {
                $(this).keypress();
                var v = $(this).val();
                if (/\.$/.test(v))
                {
                    $(this).val(v.substr(0, v.length - 1));
                }
            });
    }
js检验金额合法性 只能是正数 或小数
posted on 2017-05-19 11:03  熊哥club  阅读(313)  评论(0编辑  收藏  举报

熊哥club Fork me on GitHub