Adding email field validation in WPForms (WordPress plugin) can be done in a few different ways — depending on what kind of validation you need (basic, custom, or conditional).

Here’s a step-by-step guide 👇

1. Basic Email Validation (Built-in)

WPForms automatically validates the email field.

Steps:

Go to your WordPress Dashboard → WPForms → All Forms.

Edit your form.

Add an Email field from the Add Fields panel (or use the one already in your form).

Click on the Email field to open its settings.

Ensure “Required” is checked (so users can’t leave it blank).

WPForms automatically ensures:

Email contains “@” and a valid domain (e.g., example@gmail.com).

Invalid emails will show an error like:
“Please enter a valid email address.”

 2. Add Custom Email Validation (e.g., block specific domains)

If you want custom logic (e.g., no Yahoo or Gmail emails), you can add a small PHP snippet.

Add this code to your functions.php or a custom plugin:

function custom_wpforms_email_validation( $field_id, $field_submit, $form_data ) {
// Only apply to specific form and field (optional)
if ( absint( $form_data[‘id’] ) === 123 && $field_id === ‘1’ ) {
$email = sanitize_email( $field_submit );
$blocked_domains = array( ‘yahoo.com’, ‘gmail.com’ );
$domain = substr( strrchr( $email, “@” ), 1 );

if ( in_array( strtolower( $domain ), $blocked_domains, true ) ) {
wpforms()->process->errors[ $form_data[‘id’] ][ $field_id ] = esc_html__( ‘Sorry, emails from this domain are not allowed.’, ‘wpforms’ );
}
}
}
add_action( ‘wpforms_process_validate_email’, ‘custom_wpforms_email_validation’, 10, 3 );

What this does:

Validates the email field before form submission.

If the email domain matches a blocked list, it shows a custom error message.

Change:

123 → your form ID.

‘1’ → your field ID.

Add/remove domains in $blocked_domains.

 3. Advanced Validation Options

You can also:

Use Regex (regular expressions) to enforce patterns (e.g., company emails only).

Use Conditional Logic (in Pro version) to show/hide other fields based on the email.

Example (Regex for company domain only)

function wpforms_company_email_validation( $field_id, $field_submit, $form_data ) {
if ( absint( $form_data[‘id’] ) === 123 && $field_id === ‘1’ ) {
if ( ! preg_match( ‘/@company\.com$/i’, $field_submit ) ) {
wpforms()->process->errors[ $form_data[‘id’] ][ $field_id ] = esc_html__( ‘Please use your company email address.’, ‘wpforms’ );
}
}
}
add_action( ‘wpforms_process_validate_email’, ‘wpforms_company_email_validation’, 10, 3 );