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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:52:19+00:00 2026-06-05T15:52:19+00:00

I am trying to validate an e-mail address using javascript. The problem is the

  • 0

I am trying to validate an e-mail address using javascript. The problem is the if statements aren’t executing correctly. If I delete the ‘else statement’ the code runs correnctly and the page does not load with errors. If I include the ‘else statement’ the else statement never executes and the status bar says that the page loads with errors. I was wondering if anyone can find any errors that I am unable to pick up?

<h4>Example 4:</h4>
<div style="border:3px dashed #aaa; width:200px;">
    <div id="text">e-mail: <input id="email" onblur="verifyEmail()"/></div>
    <div id="verification" > </div>
</div>

<script type="text/javascript">
function verifyEmail(){
    var email = document.getElementById("email").value;
    var atPos=0;
     var dotPos=0;

    atPos = email.indexOf("@");
    dotPos = email.lastIndexOf(".");

    if(atPos<=3 || dotPos<atPos+2 || dotPos+2>=email.length){
        document.getElementById("verification").innerHTML = "Invalid E-mail Address";
    }else{
        document.getElementById("verification").innerHTML = "Valid";
    }

}



</script>
  • 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-05T15:52:20+00:00Added an answer on June 5, 2026 at 3:52 pm

    try this

    function validateEmail(email) { 
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
    ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
    -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    } 
    

    Demo : Here is the demo

    OR a more simpler way is

    function validateEmail(email) 
    {
        var re = /\S+@\S+\.\S+/;
        return re.test(email);
    }
    

    if you are using HTML5 try <input type="email"... please note. this one works if the input is in a form tag with a submit button and isn’t handled by JS

    <input type="email" placeholder="me@example.com">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I am trying to validate a form using PHP. The problem
I'm trying to use Ben Keen's RSV Jquery plug-in to validate an e-mail address
I am trying to validate e-mail addresses on my website and I have been
I'm trying to validate a simple XML file against an XML schema using the
I'm trying to validate my JSON API using node.js + json-schema.js from commonjs-utils. Just
Hi I am using razor and trying to use regular expression to validate email
I'm trying to validate that an email address is in the correct format by
i am trying to validate a form text box using jquery validator, it works
am trying to validate recaptcha with ajax, the only problem am facing is that
I am trying to send an email using c# using the following code. MailMessage

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.