限制input只能输入金额(类似:100.00|100.9|100)

$(".inputmoney").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));
    }
});
posted @ 2016-10-24 10:42  添天灯  阅读(3786)  评论(0编辑  收藏  举报