<?php
// This function tests whether the email address is valid
function isValidEmail($email){
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
if (eregi($pattern, $email)){
return true;
}
else {
return false;
}
}?>
<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>
<?php
if (isset($_POST['submitemail']))
{
if (isValidEmail($_POST['email'])){
echo "<tr><td>The email: ".$_POST['email']." is valid!</td></tr>";
}
else{
echo "<tr><td>The email: ".$_POST['email']." is invalid!</td></tr>";
}
}
?> <tr><td><input type="submit" name="submitemail" value="Validate email"></td></tr>
</table>
</form>
</body>
Monday, April 18, 2011
Email validation with PHP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment