# Require a Work Email in Gravity Forms

> Asks for a company email address instead of Gmail, Yahoo or other free webmail in Gravity Forms email fields, for B2B lead and demo request forms.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, validation, leads
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-business-email-only/

## Code

```php
$wpide_gf_free_providers = array( 'gmail.com', 'googlemail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'live.com', 'aol.com', 'icloud.com', 'gmx.com', 'proton.me', 'protonmail.com', 'mail.com', 'yandex.com' );

add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) use ( $wpide_gf_free_providers ) {
    if ( 'email' !== $field->type || ! $result['is_valid'] ) {
        return $result;
    }

    $classed = false;
    foreach ( $form['fields'] as $f ) {
        if ( false !== strpos( ' ' . $f->cssClass . ' ', ' work-email ' ) ) {
            $classed = true;
            break;
        }
    }
    if ( $classed && false === strpos( ' ' . $field->cssClass . ' ', ' work-email ' ) ) {
        return $result;
    }

    $email  = strtolower( trim( is_array( $value ) ? (string) reset( $value ) : (string) $value ) );
    $domain = (string) substr( strrchr( $email, '@' ), 1 );

    if ( $domain && in_array( $domain, $wpide_gf_free_providers, true ) ) {
        $result['is_valid'] = false;
        $result['message']  = 'Please use your work email address.';
    }

    return $result;
}, 10, 4 );
```

## Notes

Add the CSS class work-email to an email field in the form editor (Appearance tab) to check only that field; without the class every email field is checked.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a Work Email in Gravity Forms" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
