Elementor Forms: Require a Business Email Address
Rejects Elementor Pro form submissions that use free email providers such as Gmail or Yahoo, with a clear message under the field, for B2B lead forms.
Opens WPIDE on
Code
// Free email domains to refuse.
$wpide_el_free_domains = array( 'gmail.com', 'googlemail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'live.com', 'aol.com', 'icloud.com', 'gmx.com', 'mail.com', 'proton.me', 'protonmail.com' );
$wpide_el_free_message = 'Please use your work email address.';
add_action( 'elementor_pro/forms/validation/email', function ( $field, $record, $ajax_handler ) use ( $wpide_el_free_domains, $wpide_el_free_message ) {
$email = isset( $field['value'] ) ? strtolower( trim( (string) $field['value'] ) ) : '';
if ( '' === $email || false === strpos( $email, '@' ) ) {
return;
}
$domain = substr( strrchr( $email, '@' ), 1 );
if ( in_array( $domain, $wpide_el_free_domains, true ) ) {
$ajax_handler->add_error( $field['id'], $wpide_el_free_message );
}
}, 10, 3 );
Notes
Applies to every Email field in every Elementor form. Edit the domain list to suit your audience.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.