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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:08:31+00:00 2026-06-07T08:08:31+00:00

I have a form with JS functions for checking empty fields and submit form

  • 0

I have a form with JS functions for checking empty fields and submit form without refreshing all page, I’m looking for a way to integrate email check function into what I’m having now:

$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#EBEBEB"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#EBEBEB"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#EBEBEB"});
  });

  $(".button").click(function() {
        // validate and process form
        // first hide any error messages
    $('.error').hide();
        }

      var name = $("input#name").val();
        if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
        var email = $("input#email").val();
        if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
        var phone = $("textarea#phone").val();
        if (phone == "") {
      $("label#phone_error").show();
      $("textarea#phone").focus();
      return false;
    }

        var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
        //alert (dataString);return false;

        $.ajax({
      type: "POST",
      url: "process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Email sent</h2>")
        .hide()
        .fadeIn(1000, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
    });
});
runOnLoad(function(){
  $("input#name").select().focus();
});

Thanks for help.

  • 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-07T08:08:32+00:00Added an answer on June 7, 2026 at 8:08 am

    To check an email, you can use:

    var emailReg = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i
    
    function isEmail(email) {
      return emailReg.test(email);
    }
    //call isEmail wherever you need it
    

    If I may comment further on your code, I would recommend you cache your selectors and reuse them:

    var input = $('input.text-input');
    input.css({backgroundColor:"#EBEBEB"}).focus(function() //... and so on
    

    Also, if your DOM is correctly structured, you do not have to call your ids with input selectors, it just slows down your implementation because its iterating over every input in the DOM than just getting it directly. That means:

    $("label#phone_error") // don't do this
    $("#phone_error") // do this
    

    Also, you can use a data object to pass to jquery, so rather than

    var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
    

    Do this:

    $.ajax(yoururl, {data: 
      {
        name: name,
        email: email,
        phone: phone
      }, // and so on
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions hooked on the submit event of a form. Each function
I'm trying to have two functions checking each form input, one for onchange() and
I have JavaScript form validation functions like so: function validate_name(field) { if (field ==
I have atleast 16 functions of the following form. bool Node::some_walker( Arg* arg1 )
I have a form where the submit button triggers a function. Let's call it
I have a form where the submit button triggers a function. Let's call it
I have a form with a submit button. I have called a function on
I have a form submit, where it get the values from the form and
I have a form which I want to submit only if a condition is
I have a form with several submit buttons. I would like the button's click

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.