Possible Duplicate:
Validate email address in Javascript?
This is my first post and I have a small issue. I'm trying to validate an email address on a form, but with no luck. I found this snippet on the internet but it doesn't seem to be working. I'm using Javascript at the moment to validate it. I don't usually use JS, so any help would be appreciated.
<script type="text/javascript">
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(inputText.value.match(mailformat))
{
document.forms.emailform();
return true;
}
else
{
alert("You have entered an invalid email address!");
document.forms.emailform();
return false;
}
}
<?php
$addemail .= '
<form method="post" action="cart2.php" name="emailform" onsubmit="return validateEmail">
';
$addemail .= '
E-mail Address: <input type="text" name="email" value="'.$row6['email'].'" size="19" /><input type="hidden" name="cartid" value="'.$cart.'" />';
if ( $emailerror != '' )
{
$addemail .= '<img src="images/email_error.png" width="16" height="16" hspace="4" alt="E-mail Error" />';
}
$addemail .= '
<input type="image" name="Add E-mail Address" alt="Add E-mail Address" src="images/addemail.gif" style="vertical-align:middle" />
</form>
';
if ( $row6['email'] == '' )
{
$emailpresent = 0;
}
else
{
$emailpresent = 1;
}
}
$addemail .= '
</td>
</tr>
';
}
?>