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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:16:42+00:00 2026-06-17T10:16:42+00:00

How can I validate forms with jQuery plugin with ids that have a name

  • 0

How can I validate forms with jQuery plugin with ids that have a name pattern, like #formNewHouse1, #formNewHouse2,.. ?

This code is working with a single type (normal) form:

$("#formNewHouse").validate({
    rules: {
        formNewHouseName: {
            required: true
        },
        formNewHouseAddress: {
            required: true
        }
    },
    messages: {
        formNewHouseName: {
            required: "Please type a name"
        },
        formNewHouseAddress: {
            required: "Please type an address"
        }
    }
});   

I need something like this, where X = 2,3,6,18,19,… (IDs from DB) how can I achieve this?

$("#formNewHouseX").validate({
    rules: {
        formNewHouseNameX: {
            required: true
        },
        formNewHouseAddressX: {
            required: true
        }
    },
    messages: {
        formNewHouseNameX: {
            required: "Please type a name"
        },
        formNewHouseAddressX: {
            required: "Please type an address"
        }
    }
}); 

Thanks in advance.

  • 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-17T10:16:43+00:00Added an answer on June 17, 2026 at 10:16 am

    Also, similar to this question with a working answer:

    jQuery Validate set rule using wildcard to find target fields


    Here’s an answer along with something the others are lacking… a working demo:

    Use jQuery’s .each() method to initialize .validate() on all matching forms.

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

    HTML:

    <form id="formNewHouse1">
        <input type="text" class="myclass" name="formNewHouseName" />
        <input type="text" class="myclass" name="formNewHouseAddress" />
    </form>
    
    <form id="formNewHouse2">
        <input type="text" class="myclass" name="formNewHouseName2" />
        <input type="text" class="myclass" name="formNewHouseAddress2" />
    </form>
    

    jQuery:

    var myoptions = {
        // contains options for all forms
    };
    
    $("form[id^=formNewHouse]").each(function() {
        $(this).validate(myoptions);
    });
    
    // the following method must come AFTER .validate()
    $('form').find('.myclass').each(function() {
        $(this).rules('add', {
            required: true,
            digits: true, // just another example rule
            messages: {
                required: "Required input",
                digits: "Please only enter digits"
            }
        });
    });
    

    jsFiddle DEMO

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

Sidebar

Related Questions

You can validate a model object with EF 5 Code-First like that: var validationResult
I found the jquery validation plugin ( http://plugins.jquery.com/project/validate ) and thought that this would
I am trying to use this jQuery plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation so I can validate a
I often use this jQuery validation plugin to validate forms and it works great.
I'm looking for a plugin for jQuery that can validate as a key is
I have a jsp file: validate.jsp- var rollNo=document.forms[result_form][studentRollno].value; var name=document.forms[result_form][studentName].value; $(#student_result).load(result.jsp?rollNo=+rollNo+&name=+name); As you can
I am using jQuery Validate plugin to validate my form, how can i validate
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
I'm using the jQuery Validation plugin on my forms. I have some groups of
I'm using the jQuery validation plugin to validate a form, and I'd like to

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.