js校验表单数据

//添加验证规则

jQuery.validator.addMethod("chcharacter",function (value, element) {
var tel = /^[\
-\]+$/i;
return this.optional(element) || (tel.test(value));
}, "
只能填写中文字符");

//校验表单数据

$("#register_form").validate({
errorPlacement: function(error, element){
var error_td = element.parent('dd');
error_td.find('label').hide();
error_td.append(error);
},
rules : {
parentMemberNum:{
required : true,
},
},
messages : {
parentMemberNum : {
required : '关联号不能为空',

},
}
});
//表单提交
$("#submitBtn").click(function(){
if ($("#form").valid()) {
//ajax提交表单数据,如果校验通过
    $.ajax({
        url: '${base}/authen/member/unionpay/submitCaptcha',
        type: "post",
        data: $('#unionpayForm').serialize(),
        dataType: "json",
        success: function (data) {
            console.log(data);
            if (data.url == undefined) {
                alert(data.message);
            } else {
                location.href = '${base}' + data.url;
            }
        }
    })

    return false;
}
 

 

 

 

 

//自定义校验规则

 

你可能感兴趣的:(js校验表单数据)