validate自定义规则

$(function () {
var warningimg = "<img src='/Images/warning.png' alt='警告' class='warningimg' /> <span class='warningfont'>{0}</span>";
var righting = "<img src='/Images/right.png' alt='警告' class='rightimg' /> <span class='warningfont'>{0}</span>";
$("#form1").validate({
rules: {
txtNumList: {
required: true
},
txtMsgContent: {
required: true,
hasSignature: true
}
},
messages: {
txtNumList: {
required: jQuery.format(warningimg, "请输入电话号码!")
},
txtMsgContent: {
required: jQuery.format(warningimg, "请输入内容!"),
hasSignature: jQuery.format(warningimg, "内容必须带签名!")
}
},
errorPlacement: function (error, element) {
error.appendTo(element.parent().prev());
}
});
})

//判断是否有签名
jQuery.validator.addMethod("hasSignature", function (value, element) {
var reg = /\[(.*?)\]/gi;
return this.optional(element) || (value.match(reg));
}, "必须带签名!");

posted @ 2013-12-18 14:24  清晓zzz  阅读(263)  评论(0编辑  收藏  举报