Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new options isEmail, if is added options tags must be email #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ Optionally set a *placeholder* attribute on the `input` that gets created for ta

Defaults to *null*

### isEmail (boolean)

When enabled, tags must be email format.

Defaults to *false*


## Events

Expand Down
13 changes: 13 additions & 0 deletions js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
readOnly : false, // Disables editing.
removeConfirmation: false, // Require confirmation to remove tags.
tagLimit : null, // Max number of tags allowed (null for unlimited).
isEmail : false, // When is true tags must be email.

// Used for autocomplete, unless you override `autocomplete.source`.
availableTags : [],
Expand Down Expand Up @@ -436,6 +437,12 @@
return Boolean($.effects && ($.effects[name] || ($.effects.effect && $.effects.effect[name])));
},

_isEmail: function (str) {
var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var isEmail = regex.test(String(str).toLowerCase());
return isEmail;
},

createTag: function(value, additionalClass, duringInitialization) {
var that = this;

Expand All @@ -449,6 +456,12 @@
return false;
}

if (this.options.isEmail) {
if(!this._isEmail(value)){
return false;
};
}

if (!this.options.allowDuplicates && !this._isNew(value)) {
var existingTag = this._findTagByLabel(value);
if (this._trigger('onTagExists', null, {
Expand Down