JQuery validate表單驗證

     //添加驗證規則
        $.validator.addMethod("macaoMobile", function (value, element) {
            var reg = /^6\d{7}$/;
            return reg.test(value);
        }, "");

        //表單驗證
        $("#formMobile").validate({
            rules: {
                mobile: {
                    required: true,
                    macaoMobile: true
                },
                realName: {
                    required: true
                }
            },
            messages: {
                mobile: {
                    required: '<i class="fa fa-exclamation-circle"></i>接收手機號碼不能為空',
                    macaoMobile: '<i class="fa fa-exclamation-circle"></i>請正確填寫接收手機號碼'
                },
                realName: {
                    required: '<i class="fa fa-exclamation-circle"></i>姓名不能爲空'
                }
            }
        })

if (!$("#formMobile").valid()) {
    window.location.href = "#buyerInfo";
    return;
}

 

posted @ 2018-09-22 10:39  心有八千里路  阅读(121)  评论(0编辑  收藏  举报