Fix regex in jquery validation plugin with twitter bootstrap popover -
i have code shows popover when there white space.
$.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 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'); }); } }); what happens is, popover doesnt destroyed once there no whitespace. doing wrong?
this regular expression valid both white-space , empty string.
if want match white-space, should use regex: /^\s+$/
Comments
Post a Comment