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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T05:50:23+00:00 2026-06-19T05:50:23+00:00

NOTE Please see this question for a bit of background… So my (very basic)

  • 0

NOTE Please see this question for a bit of background…

So my (very basic) form validation is working – sort of.

When checking the input value for the email address field, I want to make sure that the email address has a value (i.e. is not blank) and contains @ and . characters so I did this…

<div width="100%" class="con1">

    <div class="lable">
        <label for="email">Email Address *</label>
    </div>
    <input  type="text" name="email" class="span4">

</div>

<script>

$('input[type=submit]').click(function() {
    var parentname = $(this).parent('div');
    console.log('Form used: ' + parentname);

    var email = 0,

    // Validate email
    if ($('.' + parentname.attr('class') + ' #email').val() == '')
    {
        alert('Please enter a valid email address');
    }
    else
    {
        if (($('.' + parentname.attr('class') + ' #email').val().contains('@')) && ($('.' + parentname.attr('class') + ' #email').val().contains('.')))
        {
            email = 1;
        }
        else
        {
            alert('Please enter a valid email address');
        }
    }
});
</script>

It looks a little weird but complexity as mentioned in the linked question above required me to think a little differently with my selectors.

Basically $('.' + parentname.attr('class') + ' #email') is the same as writing (in the case I’m using $('.con1 #email') as the selector which I believe to be correct based on my HTML structure.

I tried working with $('.' + parentname.attr('class').child('#email') but then kept getting an error that said the element had no method ‘child’

I wrote this based on a previous form I’d created where I’d used the same principle in effect, to block emails coming from yahoo.com because I was getting a lot of spam from there:

if ($("#contact-email").val().contains("yahoo.com")) {
     $(".errmsg").text("Domain yahoo.com has been banned due to excessive spam, please use another domain.");
}
else
{
    email = 1;
}

While the 2nd sample that I’ve pasted here works, the first one that validates the email field more thoroughly keeps returning this error:

Uncaught TypeError: Cannot call method ‘contains’ of undefined

I can’t understand how this could work in one site and not another. I feel like I’m missing something so would appreciate it if anyone can see what that might be.

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-19T05:50:24+00:00Added an answer on June 19, 2026 at 5:50 am

    The elements should have an id="email" to allow the selector:

    $('.' + parentname.attr('class') + ' #email')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: For background information please see this related question: How to get LINQPad to
Please note this is not a question about online/hosted SVN services. I am working
[Please note that this is a different question from the already answered How to
Please note: This is a question about the Eclipse plugin Subversive , and not
Please note that this question is from 2008 and now is of only historic
NOTE: Before reading this question please note that I have read the previous questions
NOTE: For more answers related to this, please see Special Characters in Google Calculator
Note: please keep in mind that this is not a generic question on the
(Please note that the behavior described in this question only appeared because of something
Please note, this question is regarding the shipping cost, not price. There is an

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.