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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:25+00:00 2026-06-09T23:48:25+00:00

Possible Duplicate: Validate email address in Javascript? I have an HTML form that uses

  • 0

Possible Duplicate:
Validate email address in Javascript?

I have an HTML form that uses PHP/MySQL to post to a database. In the email section of the form, I want the user to be displayed an error message if he or she types in an email address that is not in valid email address format. I am modeling off of a code like this, but I cannot get it work.

Note that whenever I hit the submit button on the form, the form submits, and the PHP action works fine. The problem is I can enter anything I like in the form and it will pass fine. I would like for it to display the error message “Not a valid email address”. I understand I can validate via PHP too, but I would like to validate on the client side as well.

Can anyone assist?

    <script type="text/javascript">
function validateEmail()
{
var x=document.forms["test"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
 {
alert("Not a valid e-mail address");
return false;
 }
 }
  </script>


  <form name"test" action="roads.php" onsubmit="return validateEmail();" method="post">

  <input type="text" name="email" placeholder="Enter your e-mail" />

   <input type="submit" value="Show Me!" />

   </form>
  • 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-09T23:48:27+00:00Added an answer on June 9, 2026 at 11:48 pm

    you are missing a = in html, which doesn’t make to form name test..and javascript can’t find the form of name test, and throws error…check console log for javascript errors..

    <form name"test" action="roads.php" onsubmit="return validateEmail();" method="post">
    
    <form name="test" action="roads.php" onsubmit="return validateEmail();" method="post">
    

    Working code

    • 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: Validate email address in Javascript? I am trying to use this javascript
Possible Duplicate: Is there a php library for email address validation? How to validate
Possible Duplicate: JQuery validate e-mail address regex hi i have an input filed in
Possible Duplicate: Editing MySQL recode using a HTML form Like to know how to
Possible Duplicate: PHP validation/regex for URL Hi, in my form I have a url
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: Regular expression to match hostname or IP Address? I need to validate
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.