Skip to content

Instantly share code, notes, and snippets.

@areichman
Created August 20, 2014 17:24
Show Gist options
  • Save areichman/43e912ec98f1e50a259c to your computer and use it in GitHub Desktop.
Save areichman/43e912ec98f1e50a259c to your computer and use it in GitHub Desktop.
Format an input tag list (either comma-delimited or an array) as an output array with blanks and whitespace removed
function reformatTags(tags) {
var _tags = (tags || '').toString().trim().replace(/\s*,\s*/g, ',').replace(/^,|,$/g, '').split(',');
if (_tags[0] === '' && _tags.length === 1) _tags = []; // hack for empty form submissions
return _tags;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment