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 8175081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:38:18+00:00 2026-06-06T22:38:18+00:00

I have two bits of code: a form and a jQuery function. My problem

  • 0

I have two bits of code: a form and a jQuery function.

My problem is that I would like to get class attributes and use them on the form validation function. I am using Validity JS for validation.

This is what I have:

<input type="text" name="name" value="" id="field_01" class=".require().minLength(5)" />

and in the JS function:

var checks_to_apply = $("#field_01").attr("class").split(" "), 
i, l;

var checks = "";

for (i = 0, l = checks_to_apply.length; i < l; i++) {

        checks += checks_to_apply[i];
    }
$("#field_01")+checks;
...
...

The right behaviour here is not respected.

This is what I get from a “checks” alert:

.require().minLength(5)

but executing in that way it is not the same as doing it directly in the jQuery function like:

$("#field_01").require().minLength(5);

Where am I wrong, I think that the problem in the method may be because it is seeing .require().minLength(5) as a string and not as jQuery code to execute.

Any idea on how to fix it, please?

  • 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-06-06T22:38:20+00:00Added an answer on June 6, 2026 at 10:38 pm

    as you are executing these functions on a particular object you would need to create the whole argument as an string and execute it via eval():

    var checks_to_apply = $("#field_01").attr("class").split(" "), 
    i, 
    l;
    
    var checks = "$('#field_01')";
    
    for (i = 0, l = checks_to_apply.length; i < l; i++) {
       checks += checks_to_apply[i];
    }
    eval(checks);
    

    But i would advise you to use a different validation plugin, because you are misusing the class attribute: Check out http://jquery.bassistance.de/validate/demo/ for a much better and cleaner annotation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two separate (but similar) bits of jQuery code. They both work, but
What would be the best code to have two bits of text in a
I have two bits of code. First a standard copy paste from cell A
I have the following code that simply uses a jquery ui modal dialog to
I have two classes (MVC view model) which inherits from one abstract base class.
I have two questions. 1) I found a little gem of code for how
I have Clojure function that takes a sequence of numbers chops it into the
In my mind these two bits of code should work the same: window.location =
What would you recommend as the best way to refactor these two bits of
I have a 'widget' that comprises an html/css block of code. It is a

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.