Add Custom Validation Rule to CF7
Adds a custom validation rule to Contact Form 7
PHP
function custom_email_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
if ($type == 'email*' && $_POST[$name] != '') {
if (strpos($_POST[$name], 'example.com') !== false) {
$result->invalidate($tag, "We don't accept example.com email addresses");
}
}
return $result;
}
add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2);
add_filter('wpcf7_validate_email', 'custom_email_validation_filter', 10, 2);
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY