using the attribute class element as an array
<p>I noticed that some validation tools use the "class" attribute to pass options to validation scripts.</p>

<p>Example:</p>

<pre><code>&lt;input class="input-field validate[required, email]" name="" type="text" /&gt;
</code></pre>

<p>the "required" and "email" would be picked up by the script as setting options.</p>

<p>I was wondering is there an easy way to achieve this or maybe this is already available in jQuery?
I want to use this as a means of passing certain settings to my script.</p>

<p>Any help would be appreciated,
Thanks</p>

<p><strong>Edit:</strong></p>

<p>Thanks @loseb your example works great.
Another thing I am trying to achieve by doing some small modification to your example:</p>

<pre><code>function classAttributes( classString, className ) {
    var data;
    var regex = new RegExp(className+"\[(.*?)\]");
    var matches = classString.match(regex);

    if ( matches ) {
        //matches[1] refers to options inside [] "required, email, ..."
            var spec = matches[1].split(/,\s*/);

            if ( spec.length &gt; 0 ) {
                data = spec;
            }
    }

    return data;
}
</code></pre>

<p>any idea why "new RegExp(className+"[(.*?)]");" doesnt work. var matches is blank.</p>

<p><strong>Edit:</strong>
second part of the question moved to:
<a href="http://stackoverflow.com/questions/8328014/javascript-regex-pattern-with-a-variable-string-not-working">javascript regex pattern with a variable string not working</a></p>
