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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:48:32+00:00 2026-06-08T07:48:32+00:00

Possible Duplicate: Validate email address in Javascript? I am trying to use this javascript

  • 0

Possible Duplicate:
Validate email address in Javascript?

I am trying to use this javascript to check for a valid email, but what I don’t need it to do is check to see if the field is blank in the form in case someone doesn’t have an email address (don’t ask).

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}

function validate_form(thisform)
{
with (thisform)
{
  if (validate_email(email,"Not a valid e-mail address.")==false)
  {email.focus();return false;}
}
}

I tried to adjust the apos<1 to less than 1 or nothing at all and that didn’t seem to work.

  • 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-08T07:48:36+00:00Added an answer on June 8, 2026 at 7:48 am

    Just check whether it is empty, and otherwise apply your email regex/validation function on it.

    Also, you should a) not use with and b) not alert from the test function.

    function test_email(address) {
        var atpos = address.indexOf("@"),
            dotpos = address.lastIndexOf(".");
        if (atpos < 1) // "@" at position 0 or not found (-1)
            return false;
        if (dotpos-atpos < 2) // last "." before position 2 or not found (-1)
            return false;
        if (atpos > dotpos) // last "." before the "@"
            return false;
        return true;
    }
    
    function validate_form(thisform) {
        var input = thisform.email;
        if (input.value) // != ""
            if (!test_email(input.value)) {
                alert("Not a valid e-mail address.");
                email.focus();
                return false;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Validate email address in Javascript? I have javascript for email validation :
Possible Duplicate: Regular expression to match hostname or IP Address? I need to validate
Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: Check whether the string is a unix timestamp i need validate a
Possible Duplicate: How to use a regular expression to validate an email addresses? \A[\w.-]+\w@[a-z\d\-.]+\.[a-z]+\z
Possible Duplicate: How to use a regular expression to validate an email addresses? I
Possible Duplicate: php validate integer Currently I'm using this method: Validate the input using
Possible Duplicate: how can i validate a url in javascript using regular expression I
Possible Duplicate: JQuery validate e-mail address regex hi i have an input filed in
Possible Duplicate: Modify regex to validate email? $email = $_POST[email]; if(preg_match([@{1}],$email)) echo There is

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.