Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@
availableTags: sampleTags,
removeConfirmation: true
});

//-------------------------------
// Regex enabled
//-------------------------------
$('#regexEnabled').tagit({
regexEnable: true,
regexPattern: /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9]+(\.?[a-zA-Z0-9]+)?$/g,
onRegexFailure: function(evt, ui) {
$("#regexMessage").text("Wrong email!").fadeIn().delay(1000).fadeOut();
}
});

});
</script>
Expand Down Expand Up @@ -256,6 +267,21 @@ <h3>Remove Confirmation</h3>
</ul>
</form>

<hr>
<h3>Regex enabled</h3>
<form>
<p>
With the option regexEnable you can set any regular expression in the regexPattern property to filter the input.
</p>
<ul id="regexEnabled">
<li>[email protected]</li>
<li>[email protected]</li>
</ul>
<div style="height:5px">
<p id="regexMessage" style="{display: hidden}"></p>
</div>
</form>

</div>


Expand Down
16 changes: 16 additions & 0 deletions js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
// Used for autocomplete, unless you override `autocomplete.source`.
availableTags : [],

regexPattern : null, // Holds the regex to be utilized when regexEnable is true
regexEnable : false, // Enables regex
regexObj : null, // To hold RegExp() object

// Use to override or add any options to the autocomplete widget.
//
// By default, autocomplete.source will map to availableTags,
Expand Down Expand Up @@ -128,6 +132,10 @@

if (this.options.readOnly) this.tagInput.attr('disabled', 'disabled');

if (this.options.regexEnable) {
this.options.regexObj = new RegExp(this.options.regexPattern);
}

if (this.options.tabIndex) {
this.tagInput.attr('tabindex', this.options.tabIndex);
}
Expand Down Expand Up @@ -462,6 +470,14 @@
return false;
}

if (this.options.regexEnable && value !== '') {
that.options.regexObj.lastIndex = 0;
if (!that.options.regexObj.test(value)) {
this._trigger('onRegexFailure', null, {duringInitialization: duringInitialization});
return false;
}
}

if (this.options.tagLimit && this._tags().length >= this.options.tagLimit) {
this._trigger('onTagLimitExceeded', null, {duringInitialization: duringInitialization});
return false;
Expand Down
Loading