需要正则表达式来过滤掉.ru和其他垃圾邮件地址

I already am using php's filter_var($email, FILTER_VALIDATE_EMAIL) to find out if the address is valid email.

I'm just gonna go ahead and block .ru email addresses. What regex and code should I use? Any other spammy tlds or addresses that you block would be appreciated as well.

I have tried this, but want to be sure I'm catching it correctly and catch other spammy emails.

function endsWith($haystack, $needle){
    $length = strlen($needle);
    return (substr($haystack, -$length) === $needle);
}

Thanks VG:

function russianEmail($email,$endings = array('\.ru')){
    return (preg_match('/('.implode('|', $endings).')$/i', $email))?true:false;
}

You can match multiple domain zones (or just endings) with following code:

$endings = array('\.ru'); // you can add zones here
preg_match('/('.implode('|', $endings).')$/i', $email);

This regex is also case-insensitive.

This is what I use (not all my own work however): Replace the link to russianbrides.com with whatever dark place you want to send the spammer.

function my_inArray($needle, $haystack) {
//  this function allows wildcards in the array to be searched
    foreach ($haystack as $value) {
    if (true === fnmatch($value, $needle)) {
    return true;
    }
}
return false;
}

// Blocking Wildcard Emails.

$deny = array(
"*@hotmobilephoneoffers.com",
"*@*.ru",
"*@*.su",
);

if (my_inarray (strtolower($email_from), $deny)) {
    header("location: http://www.russianbrides.com/");
    exit();
}