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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:37:10+00:00 2026-05-15T20:37:10+00:00

I can’t figure out what is missing so that when e-mail is valid it

  • 0

I can’t figure out what is missing so that when e-mail is valid it will skip the last invalid message and move to next item on form for validation:

enter code here 
    if (document.form1.email.value.length > 0) {

    var tst = document.form1.email.value;
    var okd = ['bankofamerica.com','baml.com','magner.com','ml.com','ust.com','ustrust.com']
    for (var i = 0; i < okd.length; i++) { okd[i] == okd[i].toLowerCase() }

    var emailRE = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})$/
    var aLst = emailRE.exec(tst)
    if (!aLst) {
        alert(tst + ' is not a valid e-mail')
    } else {
        var sLst = aLst[1].toLowerCase()
        for (var i = 0; i < okd.length; i++) {
            if (sLst == okd[i]) {
                //    alert(aLst[1] + ' is allowed');-->

           }
       }

            if (i == okd.length) alert(aLst[1] + ' is not allowed.  Please enter an email address with an authorized domain.')

            document.form1.email.select();
            return false;


    }   
}
  • 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-05-15T20:37:10+00:00Added an answer on May 15, 2026 at 8:37 pm

    I’d recommend placing this code into a function, maybe named ValidateEmail().

    In your loop: if you’ve determined the email is valid, return true;. This will prevent further execution. If that domain doesn’t match, have it continue looping to check the others.

    If the loop completes without returning true, you’ll know it didn’t match anything so return false; at the very end.

    EDIT: Use try/catch instead:

    if (document.form1.email.value.length > 0) {
    
        var tst = document.form1.email.value;
        var okd = ['bankofamerica.com','baml.com','magner.com','ml.com','ust.com','ustrust.com']
        for (var i = 0; i < okd.length; i++) { okd[i] == okd[i].toLowerCase() }
    
        try {
            var emailRE = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})$/
            var aLst = emailRE.exec(tst)
    
            if (!aLst)
                throw (tst + ' is not a valid e-mail');
    
            // isValidDomain will be changed to 'true' only if it matches an item in the array
            var isValidDomain = false;
    
            var sLst = aLst[1].toLowerCase()
            for (var i = 0; i < okd.length; i++) {
                if (sLst == okd[i]) {
                    isValidDomain = true;
                    // We break here because a match has been found - no need to compare against the other domain names.
                    break;
                }
            }
    
            if(!isValidDomain)
                throw (aLst[1] + ' is not allowed.  Please enter an email address with an authorized domain.');
    
            // If execution reaches here, you know it passed both tests!
            return true;
    
        }
        catch(err) {
    
            // This code block runs whenever an error occurs
    
            alert(err);
            document.form1.email.select();
            return false;
        }
    }
    

    throw basically acts like a goto command. It will jump directly to the catch(err) portion of the code.

    More info about try, catch, and throw:

    • http://www.w3schools.com/js/js_try_catch.asp
    • http://www.w3schools.com/js/js_throw.asp
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know im missing something but my friend and I can figure out what.
I think i must be missing something simple here but I can't figure out
I am really missing something with anonymous types, because I can't figure out what
I know that I can figure out today's date by [NSDate date]; but how
Can't figure out why my tags aren't showing in the form that is used
I can't figure out what I'm missing in the following code. I've got a
I'm having a strange problem that I can't figure out that popped up when
I'm having a validation issue that I can't figure out. I know I have
I coded my footer ages ago and I can figure out what I did
I'm just combining css files from other templates but I can figure out why

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.