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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:22:08+00:00 2026-06-02T01:22:08+00:00

I’m using a simple form with a name, email and comment field to send

  • 0

I’m using a simple form with a name, email and comment field to send messages from a webpage. There’s a hidden title field as well which should be empty in order for the form to be submitted – spam protection if you like.

The JQuery code I am running the form through before submitting works ok, but is currently only looking for an “@” character in the email address field. What I want is a better check for a correctly formatted email address.

Here’s the code.

    $(function() {  
    $('.error').hide();  
    $(".button").click(function() {  
    // validate and process form here  

        $('.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.indexOf('@') > 0)) {
            $("label#email2_error").show();  
            $("input#email").focus();  
        return false;  
        }  
        var message = $("textarea#message").val();  
            if (message == "") {  
            $("label#message_error").show();  
            $("textarea#message").focus();  
        return false;  
        } 
        var title = $("input#title").val()
            if(title !== "") {  
            $("input#title").focus();  
        return false;  
        } 

    var dataString = 'name='+ name + '&email=' + email + '&message=' + message;  
    //alert (dataString);return false;  
    $.ajax({  
        type: "POST",  
        url: "sendmail.php",  
        data: dataString,  
        success: function() {  
            $('#message_form').html("<div id='response'></div>");  
            $('#response').html("<div id='content_success_block' class='shadow_box'>")  
                .append("<div id='success_image'><img src='assets/misc/success.png'></div>")
                .append("<div id='success_text'>Thanks for contacting us! We will be in touch soon.</div>")
                .append("</div>")                   
            .hide()  
            .fadeIn(2500, function() {  
                $('#response');  
            }); 
        }  
    });  
    return false; 
    });

});

Any help is appreciated.

  • 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-02T01:22:10+00:00Added an answer on June 2, 2026 at 1:22 am

    The one that has worked best for “me”

    function validEmail(v) {
        var r = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
        return (v.match(r) == null) ? false : true;
    }
    

    ¡Important!

    You should really read THIS. It provides a lot of information on Regex for Emails, and why there is not really a good “be all, end all” solution. In short, you have to determine what is best for your expected users.


    Incorperated

    }  
    var email = $("input#email").val();  
    if (!validEmail(email)) {
        $("label#email2_error").show();  
        $("input#email").focus();  
        return false;  
    }  
    

    Alternate Strategy you might try: I tend to check email on keypress timeout (thus allowing the ability to fade out submit button if not all fields are ready)

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a

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.