Function stops working with 2nd if statement, works fine without...
Hey guys, so I'm trying to make a single function that will check to make sure the e-mails in both fields match AND to make sure the e-mail is in proper format. Strangely, with both if statements included the form will return no messages at all. If I comment out the if statement checking for proper format, the if statement to check for matching e-mail works just fine.
I want this all to be in one function because I'm wanting it to be executed onSubmit with the form. Let me know what you guys think, any help is greatly appreciated:
Code:
<html>
<head>
<script type="text/javascript">
function verifyEmail()
{
var x = document.forms["emailForm"]["enterEmail"].value;
var y = document.forms["emailForm"]["confirmation"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (x != y) {
var msg = "The email addresses entered do not match, please enter matching email addresses";
document.getElementById("error").innerHTML = msg;
return false;
}
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 > = x.length) {
var msg = "Improper e-mail format";
document.getElementById("error").innerHTML = msg;
return false;
}
else {
return;
}
}
</script>
</head>
<body>
<form name="emailForm" onsubmit="return verifyEmail();" method="post">
E-Mail Address: <input type="text" name="enterEmail">
Confirm E-Mail Address: <input type="text" name="confirmation">
<input type="submit" value="Submit"> <span id="error"></span>
</form>
</body>
</html>
Bookmarks