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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:17:47+00:00 2026-06-12T22:17:47+00:00

I am validating two sections of a webpage the first validation section validates however

  • 0

I am validating two sections of a webpage the first validation section validates however the second validator is not for some reason.

$(function(){



/* first validation - works*/
jVal = {
    //validate firstName
    'firstName': function(){

        //appends #firstNameInfo with .info to body
        $('body').append('<div id="firstNameInfo" class="info"></div>');

        //create variables
        var firstNameInfo = $('#firstNameInfo');
        var ele = $('#firstName');

        var patt = /^[a-zA-Z][a-zA-Z]{1,20}$/; 

        if(!patt.test(ele.val())) {
            jVal.errors = true;
            firstNameInfo.removeClass('correct').addClass('error');
            ele.removeClass('normal').addClass('wrong');
        }else{
            firstNameInfo.removeClass('error').addClass('correct');
            ele.removeClass('wrong').addClass('normal');
        }
    },

    //validate lastName
    'lastName': function() {

        $('body').append('<div id="lastNameInfo" class="info"></div>');

        var lastNameInfo = $('#lastNameInfo');
        var ele =$('#lastName');

        var patt = /^[a-zA-Z][a-zA-Z]{1,20}$/;

        if(!patt.test(ele.val())){
            jVal.errors = true;
                lastNameInfo.removeClass('correct').addClass('error');
                ele.removeClass('normal').addClass('wrong');
        }else{
            lastNameInfo.removeClass('error').addClass('correct');
            ele.removeClass('wrong').addClass('normal');
        }
    },
    //validate phone

    'phone' : function(){
        $('body').append('<div id="phoneInfo" class="info"></div>');

        var phoneInfo = $('#phoneInfo');
        var ele = $('#phone');

        var patt = /^((\+?1-)?\d\d\d-)?\d\d\d-\d\d\d\d$/;

        if(!patt.test(ele.val())) {
            jVal.errors = true;
            phoneInfo.removeClass('correct').addClass('error');
            ele.removeClass('normal').addClass('wrong');
        }else{
            phoneInfo.removeClass('error').addClass('correct');
            ele.removeClass('wrong').addClass('normal');
        }
    },

    //validate zipcode 
    'zip' : function() {
        $('body').append('<div id="zipInfo" class="info"></div>');

        var zipInfo = $("#zipInfo");
        var ele = $('#content_form #zip');

        var patt = /^\d\d\d\d\d$/;

        if(!patt.test(ele.val())){
            jVal.errors = true;
                zipInfo.removeClass('correct').addClass('error');
                ele.removeClass('normal').addClass('wrong');
        }else{
            zipInfo.removeClass('error').addClass('correct');
            ele.removeClass('wrong').addClass('normal');
        }
    },
    //submit button code
    'sendForm':function(){
        if(!jVal.errors){
            $('#content_form').submit();
        }
    },
};

$('#content_form #submit').click(function(){
    var obj = $.browser.webkit ? $('body') : $('html');
    jVal.errors = false;
    jVal.firstName();
    jVal.lastName();
    jVal.phone();
    jVal.zip();
    jVal.sendForm();

return false;

$('#firstName').change(jVal.firstName);
$('#lastName').change(jVal.lastName);
$('#email').change(jVal.email);
$('#content_form #zip').change(jVal.zip);

});

/**** Second Validation Does Not work ******/

kVal ={

    'zip' : function() {
        $('body').append('<div id="Infozip" class="info"></div>');

        var Infozip = $("#Infozip");
        var ele = $('#form #zip');

        var patt = /^\d\d\d\d\d$/;

        if(!patt.test(ele.val())){
            kVal.error = true;
                Infozip.removeClass('correct').addClass('error');
                ele.removeClass('normal').addClass('wrong');
        }else{
            Infozip.removeClass('error').addClass('correct');
            ele.removeClass('wrong').addClass('normal');
        }
    },
    //submit button code
    'send':function(){
        if(!kVal.errors){
            $('#form').submit();
        }
    },
};

$('#form button#submit').click(function(){
    var obj = $.browser.webkit ? $('body') : $('html');
    kVal.errors = false;
    kVal.zip();
    kVal.send();

return false;


$('#form #zip').change(kVal.zip);
});


}); /*main function closer*/

HTML FOR FIRST Validation -WORKING –

<div id="content_form">
            <p>
                <label class="block">
                    <input type="text" id="firstName" type="firstName" autocomplete="on" value="first name">
                </label>
                <label class="block">
                    <input type="text" id="lastName" type="lastName" autocomplete="on" value="last name">
                </label>
                <label class="block">
                    <input type="text" id="phone" type="phone" autocomplete="on" value="phone">
                </label>
                <label class="block">
                    <input type="text" id="zip" type="zip" autocomplete="on" value="zip code">
                </label> 
                <button type="submit" id="submit" value="Submit" title="submit">submit</button>
            </p>
        </div><!-- end form -->

HTML FOR SECOND Validation

<div id="form">
            <p>
                <label class="block">
                    <input type="text" id="zip" type="zip" autocomplete="on" value="zip code">
                </label> 
                <button type="submit"  id="submit" value="CHECK NOW" title="check now">check now</button>
            </p>        
        </div><!-- end form -->
  • 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-12T22:17:49+00:00Added an answer on June 12, 2026 at 10:17 pm

    You have the same id on both zip fields, which is probably causing your problems. The docs for the jQuery #id selector has this to say;

    Each id value must be used only once within a document. If more than
    one element has been assigned the same ID, queries that use that ID
    will only select the first matched element in the DOM
    . This behavior
    should not be relied on, however; a document with more than one
    element using the same ID is invalid.

    That is, your selection in $('#form #zip').change(kVal.zip); will not use the hierarchy under #form to find #zip, it will still find the first instance in the entire DOM.

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

Sidebar

Related Questions

I validate in two ways - using spring validator for custom validation and javax.validation
I'm using jQuery validation plugin. I have two images: first background of label, when
Two function should be implemented, and I am wondering what type of validation I
I have two validation groups: parent and child I have an add button that
Possible Duplicate: MVC3 custom validation: compare two dates I am trying to make a
I need to perform data validation of two tables using Selenium . Given a
I'm using the jQuery Validation JS I have two contact forms, the main one
I have two fields that I'd like to match. (already done the validation functions
I am new to rails validation. I have two fields: field :feed_entitlements, :type =>
I have a form that calls on two separate models. My validation works correctly

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.