我有这段代码,当有空格时会显示一个弹出框。
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
});
$('#validateForm').validate({
rules: {
product: {
required: true,
term: {regex: /^\s*$/}
}
},
messages: {
product: {
required: "A text is much",
term: "Please avoid spaces"
},
},
showErrors: function (errorMap, errorList) {
$.each(this.successList, function (index, value) {
$('#'+value.id+'').popover('destroy');
});
$.each(errorList, function (index, value) {
$('#'+value.element.id+'').attr('data-content',value.message).popover({
placement: 'top',
trigger: 'manual'
}).popover('show');
});
}
});
发生的情况是,一旦没有空格,弹出框就不会被破坏。我究竟做错了什么?