how do I reference jquery validate on dynamic fields

Posted on 2014-04-20
Last Modified: 2014-04-21

I'm using jquery validate on email inputs that a user can add/subtract fields. I'm not sure how I can get the jquery validate function to validate the email addresses with dynamically generated fields ... Example below of 2 fields but it can be "p_new_x" depending on x amount of field additions.

<input type="email" name="p_new_1" id="p_new_1" class="form-control" placeholder="Enter Email Address" required/>

<input type="email" name="p_new_2" id="p_new_2" class="form-control" placeholder="Enter Email Address" required/>

Open in new window


        submitHandler: function(form) {

            var data = $("#sharingForm").serialize();

                type: "POST",
                url: "app/func/func_sharing.cfc?method=sendInvite",
                data: data,
                cache: false,
                success: function() {
                error: function (xhr, ajaxOptions, thrownError) {


Open in new window

Question by:brihol44
1 Comment
LVL 27

Accepted Solution

skullnobrains earned 250 total points
ID: 40011703
something like this (probably a few typos)

  if(0 == $(this).attr('name').indexOf('p_new'))validateEmail($(this));

or use an ereg

it would be simpler to add a specific class (validateEmail for example) to all form form controls that need email validation

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
key press alert 2 32
Button function on table is in trouble 3 20
jQuery force form POST 7 43
HowTo set a global variable in javascript or jQuery 4 21
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question