So I've used many differant email validators before but none had what I needed and that was to block free hosts...so here's my code
<?php
/**
* Shawn Kurtz
* shawnkurtz[at]gmail[dot]com
*
* Copyright (c) 2007 Shawn Kurtz
* Released Under Terms of
* GNU General Public License >= v2
*/
# [version]: 1.0.0
# [last_edit]: 06.30.07@01.39
/**
* @param string $fEmail the email address to check
* @param bool $fAllowFree allow free email addresses(true/false)
* @param array $fFreeEmails array containing free emails to block
* @return bool returns false on match/free email, true otherwise
*/
function check_email($fEmail, $fAllowFree=true, $fFreeEmails=array())
{
if(empty($fFreeEmails) && $fAllowFree == false)
{
$fFreeEmails = array("yahoo.com", "hotmail.com", "gmail.com",
"inbox.com", "hotpop.com", "bigstring.com",
"mywaymail.com"
);
}
if(preg_match("/^[a-zA-Z0-9._-]+@([a-zA-Z0-9].?)+[a-zA-Z]{2,4}$/", $fEmail))
{
if($fAllowFree !== true)
{
$fDomain = explode("@", $fEmail);
$fDomain = $fDomain[1];
foreach($fFreeEmails as $fFreeEmail)
if($fDomain == $fFreeEmail) { return false; }
}
return true;
}
else { return false; }
}
$email = $_POST['email'];
// you can call it like this, just using the email
if(!check_email($email)){ echo "INVALID EMAIL ADDY/HOST NOT ALLOWED!"; }
// or like this, you can block the default free hosts
if(!check_email($email, false)){ echo "INVALID EMAIL ADDY/HOST NOT ALLOWED!"; }
// or you can block your own set of domain names
$blocked_hosts = array("yahoo.com", "blah.com", "email.com");
if(!check_email($email, false, $blocked_hosts)){ echo "INVALID EMAIL ADDY/HOST NOT ALLOWED!"; }
?>
It blocks certain free hosts, please give me your feedback on the whole thing