Best answer found here. Define a function to check for the domains.
function is_business_email($email)
{
if (
preg_match('/@hotmail.com/i', $email) ||
preg_match('/@gmail.com/i', $email) ||
preg_match('/@yahoo.co/i', $email) ||
preg_match('/@yahoo.com/i', $email) ||
preg_match('/@mailinator.com/i', $email) ||
preg_match('/@gmail.co.in/i', $email) ||
preg_match('/@aol.com/i', $email) ||
preg_match('/@yandex.com/i', $email) ||
preg_match('/@msn.com/i', $email) ||
preg_match('/@gawab.com/i', $email) ||
preg_match('/@inbox.com/i', $email) ||
preg_match('/@gmx.com/i', $email) ||
preg_match('/@rediffmail.com/i', $email) ||
preg_match('/@in.com/i', $email) ||
preg_match('/@live.com/i', $email) ||
preg_match('/@hotmail.co.uk/i', $email) ||
preg_match('/@hotmail.fr/i', $email) ||
preg_match('/@yahoo.fr/i', $email) ||
preg_match('/@wanadoo.fr/i', $email) ||
preg_match('/@wanadoo.fr/i', $email) ||
preg_match('/@comcast.net/i', $email) ||
preg_match('/@yahoo.co.uk/i', $email) ||
preg_match('/@yahoo.com.br/i', $email) ||
preg_match('/@yahoo.co.in/i', $email) ||
preg_match('/@rediffmail.com/i', $email) ||
preg_match('/@free.fr/i', $email) ||
preg_match('/@gmx.de/i', $email) ||
preg_match('/@gmx.de/i', $email) ||
preg_match('/@yandex.ru/i', $email) ||
preg_match('/@ymail.com/i', $email) ||
preg_match('/@libero.it/i', $email) ||
preg_match('/@outlook.com/i', $email) ||
preg_match('/@uol.com.br/i', $email) ||
preg_match('/@bol.com.br/i', $email) ||
preg_match('/@mail.ru/i', $email) ||
preg_match('/@cox.net/i', $email) ||
preg_match('/@hotmail.it/i', $email) ||
preg_match('/@sbcglobal.net/i', $email) ||
preg_match('/@sfr.fr/i', $email) ||
preg_match('/@live.fr/i', $email) ||
preg_match('/@verizon.net/i', $email) ||
preg_match('/@live.co.uk/i', $email) ||
preg_match('/@googlemail.com/i', $email) ||
preg_match('/@yahoo.es/i', $email) ||
preg_match('/@ig.com.br/i', $email) ||
preg_match('/@live.nl/i', $email) ||
preg_match('/@bigpond.com/i', $email) ||
preg_match('/@terra.com.br/i', $email) ||
preg_match('/@yahoo.it/i', $email) ||
preg_match('/@neuf.fr/i', $email) ||
preg_match('/@yahoo.de/i', $email) ||
preg_match('/@aim.com/i', $email) ||
preg_match('/@bigpond.net.au/i', $email)
) {
return false; // It is a free email address
} else {
return true; // It is likely a business email address
}
}
Then hook into it
function custom_email_validation_filter($result, $tag)
{
$field_name = 'company-email';
$tag = new WPCF7_Shortcode($tag);
if ($field_name == $tag->name) {
$the_value = isset($_POST[$field_name]) ? trim($_POST[$field_name]) : "";
if (!is_business_email($the_value)) {
$result->invalidate($tag, "Please enter a valid business email");
}
}
return $result;
}
add_filter('wpcf7_validate_email', 'custom_email_validation_filter', 10, 2);
add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2);
I'm checking for field names company-email
you can change this for your case