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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:12:27+00:00 2026-06-19T04:12:27+00:00

I have this script where it loops through an array and its supposed to

  • 0

I have this script where it loops through an array and its supposed to check if each of the values within the array is an email with this function:

function isEmail(email) {
  var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return regex.test(email);
}

Supposed to look through array:

$.each(arrayEmail,function(i){

    var checkEmail = isEmail(arrayEmail[i]);
    if(checkEmail != false){
    alert(arrayEmail[i]);
    var message = $('#sendMsg textarea.emailMsg').val();
        $.ajax({
            type:'post',
            url:'ajax_inviteMsg.php',
            data: 'to='+$.trim(arrayEmail[i])+'&message='+message,
            success: function(data){
                  alert(data);
            }

    });
    }
});

The alert(arrayEmail[i]); after checking if email if false or not only displays first value, which tells me that it only iterates through the if statement one, however, I’ve tested the emails and should be working doesn’t get passed through that if statement.

If the alert right after the each function, it iterates through the values corretly.

Again, the emails are true and should be iterating through the if statement as true.

I just want to know what I’m doing wrong that it only passes the if statement once if there’s multiple values in the array.

Thanks

EDIT

I also have this before the each function

<div>test@gmail.com, fresh@hotmail.com</div>


var emails = $('div').text();
var arrayEmail = emails.split(',');
  • 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-19T04:12:29+00:00Added an answer on June 19, 2026 at 4:12 am

    After you split text of div element your array becomes this:
    element0 = “test@gmail.com”
    element1 = ” fresh@hotmail.com“

    2nd element has leading space and fails to match regular expression.

    Try with this div: test@gmail.com,fresh@hotmail.com without space and you will understand.

    On the end trim string before validating it.

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

Sidebar

Related Questions

I have a script which loops through an array of words, but how do
I have a script that looks like this #!/bin/bash function something() { echo hello
I have this while loop, that basically loops through a lot of records in
I have a php script does this: Put UPC into form Submit form Check
I have a PHP script with infinite loop. I need this script running forever.
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have a bash script that looks like this: #!/bin/sh previousRelease=`git describe --tags --match
If I have a simple web page and script that looks like this: <body>
I have a script that starts Tomcat and it looks like this: rem set
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct

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.