954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Email Validate function (small error)

Hello the code below checks if the email is real but when a real email is entered for some reason or another it states undefined when the sumit button is clicked even though the email entered is real. if no email is entered is says enter a an email, if a wrong email is entered it states no a vaild email. thats the only error but cant figure why its doing that any ideas guys

<HTML>
<HEAD>
        <TITLE>Comment Form</TITLE>
<Script language = javascript>

function Validate() {
Message = ""

Message = Message + CheckEmail()


if (Message == "") {
return true
}
else {
alert(Message)
return false
}

}


function CheckEmail() {
email = document.f1.Email.value
AtPos = email.indexOf("@")
StopPos = email.lastIndexOf(".")
Message = ""

if (email == "") {
Message = "Not a valid Email address" + "\n"
return Message
}

if (AtPos == -1 || StopPos == -1) {
Message = "Not a valid email address" + "\n"
return Message
}

if (StopPos < AtPos) {
Message = "Not a valid email address" + "\n"
return Message
}

if (StopPos - AtPos == 1) {
Message = "Not a valid email address" + "\n"
return Message
} 


}



</script>
</HEAD>
<BODY BGCOLOR = White>
<form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain>
  
    <tr> 
      <td height="40" valign="top" colspan="4" align="center"><b>Email: 
        <input type="text" name="Email" size="30">
        </b></td>
    </tr>

    <tr align="center"> 
      <td height="80" colspan="2" valign="top">&nbsp;</td>
      <td valign="top" colspan="3"> 
        <input type="submit" name="Submit" value="Submit This Form">
        <input type="reset" name="Submit2" value="Reset This Form">
      </td>
    </tr>
    <tr> 
      <td height="0"></td>
      <td width="40"></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="1"></td>
      <td></td>
      <td width="10"></td>
      <td></td>
      <td></td>
    </tr>
  </table>
</form>
</BODY>
</HTML>
sukhy_1
Junior Poster in Training
63 posts since Mar 2008
Reputation Points: 10
Solved Threads: 3
 

Your answer

<HTML>
<HEAD>
<TITLE>Comment Form</TITLE>
<Script language = javascript>

function Validate() {
var Message = ""

Message = Message + CheckEmail()



if (Message == ""){
return true
}
else {
alert(Message)
return false
}

}


function CheckEmail() {
email = document.f1.Email.value
AtPos = email.indexOf("@")
StopPos = email.lastIndexOf(".")
Message = ""

if (email == "") {
Message = "Not a valid Email address" + "\n"
return Message
}

if (AtPos == -1 || StopPos == -1) {
Message = "Not a valid email address" + "\n"
return Message
}

if (StopPos < AtPos) {
Message = "Not a valid email address" + "\n"
return Message
}

if (StopPos - AtPos == 1) {
Message = "Not a valid email address" + "\n"
return Message
} 

return Message
}



</script>
</HEAD>
<BODY BGCOLOR = red>
<form name="f1" method="post" action="book.php" onSubmit="return Validate()" enctype = text/plain>
<table width="709">
<tr><td height="40" valign="top" colspan="4" align="center"><b>Email:<input type="text" name="Email" size="30"></b></td><td height="80" colspan="2" valign="top"><input type="submit" name="Submit" value="Submit This Form"></td>
<td valign="top" colspan="3"><input type="reset" name="Submit2" value="Reset This Form"></td></tr>

</table>
</form>
</BODY>
</HTML>
nikesh.yadav
Posting Whiz in Training
219 posts since Feb 2008
Reputation Points: 15
Solved Threads: 21
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You