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

  • Home
  • SEARCH
  • 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 9182703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:37:22+00:00 2026-06-17T18:37:22+00:00

I am using the jQuery Validate Plugin that is available on the official jQuery

  • 0

I am using the jQuery Validate Plugin that is available on the official jQuery website to validade my forms. Everything was going just fine until I have to pass rules, not based on a field name, but on class or id. I can’t manage to do that.

This an example of how I am passing rules to the field with name="comment".

This is my jQuery code

$("#comForm").validate({
    rules: {
        comment: {
            required: true,
            minlength: 5,
            maxlength: 500
        }
    }
});

This is my form

  <form id="comForm" action="#" method="post" >
  <textarea rows="4" name="comment" placeholder="What do you think?" class="input-xxlarge" id="defaultform"></textarea></br>
  <textarea rows="4" name="othercomment" placeholder="What do you think?" class="input-xxlarge" id="defaultform"></textarea></br>
  <input type="submit" value="Rate!" class="btn btn-primary">
  </form>

Let’s just say I want to pass the rules to every field with the default form id or to all fields with input-xxlarge class. Is that possible?

  • 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-17T18:37:24+00:00Added an answer on June 17, 2026 at 6:37 pm

    Yes it’s possible, but you really should not use duplicate id‘s… it’s invalid HTML and it will lead to JavaScript issues. Use class if you need duplicates.

    Use the built-in rules() method to add rules and assign them by class. See documentation.

    Then use jQuery’s .each() method to to apply rules to all matching elements using that same class.

    HTML:

    <form id="myform">
        <textarea class="myclass" name="field1" ></textarea>
        <textarea class="myclass" name="field2" ></textarea>
    </form>
    

    jQuery:

    $('#myform').validate({
        // your other rules and options
    });
    
    // the following method must come AFTER .validate()
    $('.myclass').each(function() {
        $(this).rules('add', {
            required: true,
            minlength: 5,
            maxlength: 500,
            messages: {
                required: "Required input",
                minlength: "Must be at least {0} characters",
                maxlength: "Must be less than {0} characters"
            }
        });
    });
    

    Working DEMO


    Also, similar to this question:

    jQuery Validate set rule using wildcard to find target fields

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

Sidebar

Related Questions

I am using the jQuery Validate() plugin. It's been working just fine, however, I
I'm using the jQuery validate() plugin for some forms and it goes great. The
I need to validate a textarea using the plugin jQuery Validate, to do that
I haven't seen a good RegEx using jQuery validate plugin that validates a phone
I am Using jquery validate() plugin . i hava a combobox in form that
I have a form that is using jQuery Validate plugin for client side validation,
I'm using the jQuery validate plugin to validate a form. My problem is that
I am using jQuery validate plugin to do custom validations on my forms. For
I am using jquery.validate.js plugin for a dialog validation. My problem is that I
I'm using jQuery Validate plugin and store Error messages in title, e.g.: <input type=text

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.