JSFiddle - React, Tailwind, and code Playground

by morrison

HTML

<input id="name" class="validate[required,length[1,255]] amp_validation_error_field" type="text" value="" title="Name" name="name">

JavaScript

$.fn.getValidateParameters = function() {
    var params = [];
    this.each(function() {
        //we'll split on spaces initially to get each class.
        var matches, length, classes = $(this)[0].className.split(' ');
        length = classes.length;

        while (length--) {
            //get second parameter of validate[]
            matches = /validate\[[^,]*,[a-z]+\[([^\]]*)\].*\]/.exec(classes[length]);

            if (matches !== null) {
                //split out the comma
                matches = matches[1].split(',');
                params[params.length] = matches;
            }
        }

    });
    
    return params;
};

console.log($('input').getValidateParameters());