Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6907609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:27:24+00:00 2026-05-27T08:27:24+00:00

I noticed that some validation tools use the class attribute to pass options to

  • 0

I noticed that some validation tools use the “class” attribute to pass options to validation scripts.

Example:

<input class="input-field validate[required, email]" name="" type="text" />

the “required” and “email” would be picked up by the script as setting options.

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.

Any help would be appreciated,
Thanks

Edit:

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

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 > 0 ) {
                data = spec;
            }
    }

    return data;
}

any idea why “new RegExp(className+”[(.*?)]”);” doesnt work. var matches is blank.

Edit:
second part of the question moved to:
javascript regex pattern with a variable string not working

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:27:25+00:00Added an answer on May 27, 2026 at 8:27 am

    If I understand you correctly this is the solution:

    var className = $('.input-field').att('class');
    var regex = /validate\[(.*?)\]/;
    var matches = className.match(regex);
    
    if (matches) {
        //matches[1] refers to "required, email" string
        var spec = matches[1].split(/,\s*/);
    
        if (spec.length == 2) {
            var attribute = spec[0]; //required or optional or anything else
            var validator = spec[1]; //actual validation type
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that some enumerations have None as a enumeration member. For example what
While reading cocoa tutorials i've noticed that some of the tutorials use AppDelegate and
I'am doing some form validation and noticed that Internet Explorer don't works correctly (as
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
I've noticed that some sites (usually banks) suppress the ability to paste text into
I have noticed that some apps like Safari and Mail show a loading indicator
I've noticed that on some websites (including SO) the link to the CSS will
I've playing around with linux and noticed that for some mysterious reason commands like
Quick question, I noticed that on some of my header directors I was getting
I'm sure some of you noticed that if you have Acrobat Reader ( or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.