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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:23:05+00:00 2026-06-07T01:23:05+00:00

I am validating an email address. But this is not validating whether I am

  • 0

I am validating an email address. But this is not validating whether I am using proper tld or not. I want to validate only for .com,.in,.org,.gov and .jo .How to do that? My code is like:

function validateConsumerEmail(){
    email = document.getElementById('customer_email').value;
    if ((email == null)||(email == "")){
        alert("Please Enter a Valid Consumer Email Address...")
        document.consumerEmail.customer_email.focus();
        return false
    }
    if (echeck(email)==false){
       email=""
       document.consumerEmail.customer_email.focus();
       return false
    }
    if(email != ''){
      var splitting = email.split('@');
      if(!isNaN(splitting[0])){
    alert('Please provide proper email address...');
    document.consumerEmail.customer_email.focus();
    return false;
      }
      if(splitting[0].length<6 || splitting[0].length > 250){
    alert('Please provide proper email address...');
    document.consumerEmail.customer_email.focus();
    return false;
       }

    }
}

where customer_email is the id of the field name.

function echeck(str) {

   var at="@"
   var dot="."
   var lat=str.indexOf(at)
   var lstr=str.length
   var ldot=str.indexOf(dot)
   if (str.indexOf(at)==-1){
      alert("Please provide valid email ID.");
      return false
   }
   if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      alert("Please provide valid email ID.");
      return false
   }

   if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
     alert("Please provide valid email ID.");
     return false
   }

   if (str.indexOf(at,(lat+1))!=-1){
     alert("Please provide valid email ID.");
     return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    alert("Please provide valid email ID.");
    return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
    alert("Please provide valid email ID.");
    return false
   }

   if (str.indexOf(" ")!=-1){
    alert("Please provide valid email ID.");
    return false
   }

  return true                   
}
  • 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-07T01:23:06+00:00Added an answer on June 7, 2026 at 1:23 am

    Try this. For validation of e-mail addresses you really want to use REGEX, because your current code allows through all kinds of invalid e-mails, and doesn’t allow many that are valid.

    That said, being able to validate truly any valid e-mail is something of a discussion point and has been for years. My example is based on an adapted version of this e-mail-matcher REGEX.

    I also simplified your code somewhat. I left out the call to echeck as you didn’t provide this. Add it back in as required.

    function validateConsumerEmail(){
    
        //prep
        var email = document.getElementById('customer_email'), error;
    
        //validate
        if (!email.value || !/^[\w\.%\+\-]+@[a-z0-9.-]+\.(com|gov|in|jo|org)$/i.test(email.value))
            error = 'Please enter a valid e-mail, with the domain .com, .in, .org, .jo or .gov';
    
        //feedback
        if (error) {
            email.focus();
            return false;
        } else {
            //OK - do something here
        }
    
    }
    

    ​

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

Sidebar

Related Questions

I'm validating a textbox for valid email with this: <asp:RegularExpressionValidator ID=RegularExpressionValidator1 ControlToValidate=txtMailCustom Text=Invalid address
I want to validate my email address through jquery unobtrusive validation . Like to
I am validating an email address using the following regex var regex=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; Now the
I want that screenCheck function show run only after Validation of #contact_email . But
I need to validate an email address which will be transmitted to several possible
This is my form validation for the email address - field email1 - what
I'm not asking about full email validation. I just want to know what are
Possible Duplicate: Validate email address in Javascript? I have javascript for email validation :
I have a requirement to validate an email address entered when a user comes
http://www.3dmark3t.com/contact.html 1 Here is my contact form I want to be able to only

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.