When collecting leads through Elementor forms, you may want to restrict users from submitting free email addresses like Gmail or Yahoo and allow only business/company emails.
This guide shows how to block free email domains using a simple PHP validation hook.
Use Case
- Lead generation forms
- B2B websites
- Filtering low-quality or personal email submissions
Add Custom Validation Code
Add the following code to your theme’s functions.php file or a custom plugin:
add_action('elementor_pro/forms/validation', function ($record, $handler) {
// Check form ID
$form_id = $record->get_form_settings('form_id');
if ($form_id !== 'your_form_id') {
return;
}
// Get form fields
$raw_fields = $record->get('fields');
$fields = [];
foreach ($raw_fields as $id => $field) {
$fields[$id] = $field['value'];
}
// Get email field value
$email = $fields['email_field_id'];
// Block free email domains
if (!preg_match('/^[a-zA-Z0-9._%+-]+@([a-zA-Z0-9.-]+\.)?[a-zA-Z]+\.[a-z]{2,}$/', $email) ||
preg_match('/@(gmail\.com|yahoo\.com|hotmail\.com|outlook\.com)$/', $email)) {
$handler->add_error('email', 'Please use an official company email address.');
$handler->add_error_message('Form submission is invalid. No email was sent.');
}
}, 10, 2);
Important Setup Notes
- Replace
your_form_idwith your actual Elementor form ID - Replace
email_field_idwith your email field ID - Make sure Elementor Pro is active (required for form hooks)
How It Works
- Hooks into Elementor form validation process
- Checks submitted email format
- Blocks common free email providers
- Shows error message and stops submission
Customize Blocked Domains
You can extend the blocked list by editing this part:
/(gmail\.com|yahoo\.com|hotmail\.com|outlook\.com)$/Example:
/(gmail\.com|yahoo\.com|hotmail\.com|outlook\.com|icloud\.com)$/Conclusion
This method is lightweight, effective, and helps improve lead quality by ensuring users submit business email addresses instead of personal ones.
It’s especially useful for agencies, SaaS platforms, and B2B websites.