The idea behind Allow Only Business Email Address in the Email Field of Elementor Forms is simple. We are going to blocklist the top popular personal email provider domain so it looks Elementor form email field only works for business emails.
As Elementor Form is available on the Pro version only, You need to have Elementor Pro. If you don’t have one you can get it from here.
we are using Elementor Pro’s action hook to achieve this goal. Put this code on your functions PHP file of the child theme.
// Validate the email fields for valid domains
add_action( 'elementor_pro/forms/validation/email', function( $field, $record, $ajax_handler ) {
// Please include the email domains you would like to block in this list
$invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook."];
// email validation
foreach($invalidDomains as $domain){
if(strpos($field['value'], $domain) !== false){
$ajax_handler->add_error( $field['id'], "Must be Business email." );
}
}
}, 10, 3 );
Here on $invalidDomains
variable put all of the TLD that you don’t want to receive email.
That’s all.