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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:21:53+00:00 2026-06-06T06:21:53+00:00

I am trying to validate email using javascript but for some reason it is

  • 0

I am trying to validate email using javascript but for some reason it is not working.

PROBLEM:When I enter VALID email address it still alerts that that my address is faulty…
What I am missing here?
Here’s the code:

    $(document).ready(function(){

    $('.info').hide();
    $('#button').click(function(){

    var name = encodeURIComponent($('#name').val());
    var email = encodeURIComponent($('#email').val());
    var message = encodeURIComponent($('#message').val());
    var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;



    //if name is empty
    if($('#name').val() == 0){

    $('.info').html('<p style="font-weight:bold;text-align:center;font-size:20px;"> Molimo unesite Vaše ime!</p>').fadeIn(1000);
    }
    //if name is less than three characters
    else if(name.length < 3){
    $('.info').html('<p style="font-weight:bold;text-align:center;font-size:20px;"> Molimo unesite ime duže od tri slova!</p>').fadeIn(1000);

    }
     // if email is empty
     if ($('#email').val() == 0){
    $('.info').html('<p style="font-weight:bold;text-align:center;font-size:20px;"> Molimo unesite Email!</p>').fadeIn(1000);

    }
    // if email AND name are empty
    if($('#email').val() == 0 && $('#name').val() == 0 ){
    $('.info').html('<p style="font-weight:bold;text-align:center;font-size:20px;"> Molimo unesite Email!<br/>Molimo unesite ime!</p>').fadeIn(1000);

    }
    //if mail adress is NOT valid
    if(reg.test(email)==false){
    //alert('please enter valid mail!');
    $('.info').html('<p style="font-weight:bold;text-align:center;font-size:20px;">Molimo unesite ispravan Mail!</p>').fadeIn(1000);
    }

            //if mail adress IS VALID (this is not working...)
    if($('#name')!= '' && reg.test(email) !=false ){

            //alert(data);
    var data = 'name=' + name + '&email=' + email + '&message=' + message;

           $.ajax({
           type:"POST",
           url:'kontakt2.php',
           cache:'false',//IE FIX
           data: data,

           success: function(){
           //alert('THX for your mail!');
           } //end sucess 
           });
           } //end if statment for VALID mail
           //return false prevent Redirection
           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-06-06T06:21:56+00:00Added an answer on June 6, 2026 at 6:21 am

    the line

    if($('#name')!= '' && reg.test(email) !=false )
    

    should probably be

    if($('#name').val()!= '' && reg.test(email) !=false )
    

    (or just if (name != '' && reg.test(email) != false ) )

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

Sidebar

Related Questions

I am trying to validate an e-mail address using javascript. The problem is the
I'm trying to create a registration form and validate input fields using javascript, but
I am trying to validate my form using jquery but I cannot get it
I am trying to validate some form fields but it always errors out on
Hi I am using razor and trying to use regular expression to validate email
Trying to get this form to validate email using the function the professor said
I am trying to validate an email address user has entered. I've done the
I'm trying to validate that an email address is in the correct format by
I'm trying to insert records into DB using AJAX. I'm not sure why, but
I am trying to validate the uniqueness of an email address in datastore. The

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.