validation.js 사용 실례

1477 단어 검증validation.js
   // 
  $.validator.addMethod('checkPro', function (value, element, param) {
        if ($('input[name="is_buy"]:checked').val() == "1") {
            var pro = $("#products").val();
            return pro != "" || pro.length > 0;
        }
        return true;
    }, '<i class="icon-exclamation-sign"></i> ');

    $('#hezuo_form').validate({
        errorPlacement: function (error, element) {
            if (element.is(':radio') || element.is(':checkbox')) { // radio checkbox 
                error.appendTo(element.parent()); //  
            } else {
                $(element).next('span').append(error);
            }
        },
        onfocusout: function (element) {
            $(element).valid();
        },
        rules: {
            title: {
                required: true,
                minlength: 3,
                maxlength: 50
            }, 
            products: {
                checkPro: true
            }
        },
        messages: {
            title: {
                required: '<i class="icon-exclamation-sign"></i> ',
                minlength: '<i class="icon-exclamation-sign"></i> 3 , 50 ',
                maxlength: '<i class="icon-exclamation-sign"></i> 3 , 50 '
            } 
        }
    });
});

좋은 웹페이지 즐겨찾기