I've been assigned to a task to do a function validating email addresses. I've been using explode and eregi in the coding.. I'm newbie in php and I hope you guys can help me.
below is my code..
<?php
function valid_mail($sentence){
$pattern= "^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$";$sentence = $_POST['email'];
$words = explode(',', $sentence);
foreach($words as $word){
if (ereg($pattern, $sentence))
{echo "yes!";}
else {echo "no!??";} }
?>
<html>
<head>
<title>Email validation form</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="emailForm">
<table>
<tr><td>Email:<input name="email"></td><tr>
<tr><td><input type="submit" name="submitemail" value="Validate email"></td></tr>
</table>
</form>
</body>
</html>


