aef-/jquery.masterblaster — pull request #11 by azaslavsky (2014-03-19 10:38:33+00:00)
Title: A few small modifications

Absolutely love this plugin. Made a few small updates for my own personal use, thought I'd add them to the repo. Feel free to cherry pick. Also, I think it'd be nice to add a license, just for the peace of mind of whoever downloads/modifies it...

Anyway, the mods are:

* Added a "maxLength" parameter that (in my opinion) deals with that issue more elegantly than setting the maxlength HTML attribute on the input field
* Made it possible to check validity after every keystroke, not just when users try to add the tag
* Switched 'keydown' events to 'keyup,' making the "tagName" parameter provided to the masterblaster events identical to what was in the input field AFTER the keypress was completed, not before
* Finally, I added a "matchRules" parameter that allows users to specify RegEx rules that all potential tag names must pass to be considered valid. The parameter is an array of strings, each of which is converted into a RegEx expression with no flags activated. An example:

```
var $mb = $( ".masterblaster-1" );
$mb.masterblaster({
tagRules: {
unique: true,
minLength: 4,
maxLength: 20
},
matchRules: [
'^[^!]*$', //Exclamation points not allowed
'^[\\S]*$', //No whitespace
'^[A-Z][a-zA-Z0-9]*$', //First letter must be uppercase
]
});
```

The above example would react as follows to users trying to input the provided example tags:
```
'cars' //invalid
'Cars' //valid!
'my cars' //invalid
'mycars' //invalid
'Mycars' //valid!
'Mycars!' //invalid
'TheseAreAllCarsThatAreReallyGreat' //invalid (longer than maxLength)
```

Also, the matchTags() method is available in the API. If users leave the 2nd argument blank, it will simply try and match the regex expression to all of the current tags, returning an array of successful matches. If the 2nd argument is an array of strings, it will match the regex to each value in the array instead. This is useful for cyclical matching to multiple regex expressions.