Check the following code that achieves what you want I havent checked your code.
Code:
<html>
<head>
<script type="text/javascript">
function formValidation()
{
var email1 = document.getElementById("email1").value;
var email2 = document.getElementById("email2").value;
var nameval = document.getElementById("name").value;
if(nameval == "" || email1 == "" || email2 == "")
{
alert('plz enter values in all the form fields');
return false;
}
if(email1 == email2)
{
if(!validateEmail(email1))
{
alert('Not a valid email address');
return false;
}
}
else
{
alert('Email values doesn\'t match..');
return false
}
alert('success');
return true;
}
//Function for validating email
function validateEmail(emailVal)
{
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (! emailVal.match(re))
{
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" method="get" action="" onsubmit="return formValidation();">
Name
<input type="text" name="name" id="name"><br>
Enter Email
<input type="text" name="email1" id="email1"><br>
Reenter Email
<input type="text" name="email2" id="email2"><br>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
Bookmarks