ReportingAnalyst
MIS
I am unable to fire the alert messages to check if the email is valid or not. secondly with nothing in the textbox when I click on the submit button, the form still gets submitted. How can I prevent this?
Thanks.
Thanks.
Code:
<script type="text/javascript">
function checkEmail(obj)
{
isEmail = /^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$/i;
notEmail = /^(((postmaster|root|hostmaster|mailer-daemon|webmaster)@(wyvernwood|frame)\.com)|.*@(.*\ .(wyvernwood|frame)\.com|localhost\.com|127\.0\.0\ .1))$/i;
if(obj.value.indexOf('@',0) == -1 ||
obj.value.indexOf('@',0) == 0 ||
obj.value.indexOf('.',0) == -1)
{
errorObj = obj;
alert("Invalid Email Address.");
return false;
}
else
if(notEmail.test(obj.value))
{
errorObj = obj;
alert("Invalid Email Address.");
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" onSubmit="return checkEmail(this);" action="add_to_plaint.asp">
Email: <input type="text" name="email" size="20">
<input type="submit" name="Submit" value="Submit" />
</form>