1. 方法添加
/*CVSS评分*/
jQuery.validator.addMethod("isCvssscore", function (value, element) {
var pattern = /^(\d(\.\d{0,2})?|10(\.0{0,2})?)$/;
return this.optional(element) || (pattern.test(value));
}, "CVSS评分只能为0-10之数,保留两位小数.");
/*CVE编号*/
jQuery.validator.addMethod("isCve", function (value, element) {
var pattern = /^CVE(-\d+){2}$/;
return this.optional(element) || (pattern.test(value));
}, "CVE编号格式为CVE-001-001");
/*CNCVE编号*/
jQuery.validator.addMethod("isCncve", function (value, element) {
var pattern = /^CNCVE(-\d+){1}$/;
return this.optional(element) || (pattern.test(value));
}, "CNCVE编号格式为CNCVE-001");
/*CNNVD编号*/
jQuery.validator.addMethod("isCnnvd", function (value, element) {
var pattern = /^CNNVD(-\d+){2}$/;
return this.optional(element) || (pattern.test(value));
}, "CNNVD编号格式为CNNVD-001-001");
/*CNVD编号*/
jQuery.validator.addMethod("isCnvd", function (value, element) {
var pattern = /^CNVD(-\d+){2}$/;
return this.optional(element) || (pattern.test(value));
}, "CNVD编号格式为CNVD-001-001");
2. 使用方式:
$("#AddForm").validate({
rules: {
cnvdtag: {
isCnvd: true
}
}
});
var $addForm = $("#AddForm");
Test.add = function (btn) {
if ($addForm.validate().form()) {
}
}