# Minimum Message Length in WPForms

> Requires WPForms paragraph fields to contain at least a few words, so you get enough detail to reply and fewer one-word junk messages.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, validation, textarea
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-message-min-length/

## Code

```php
$wpide_wpf_min_words = 5;

add_action( 'wpforms_process_validate_textarea', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_min_words ) {
    $text     = trim( wp_strip_all_tags( (string) $field_submit ) );
    $required = ! empty( $form_data['fields'][ $field_id ]['required'] );

    if ( '' === $text && ! $required ) {
        return;
    }

    if ( preg_match_all( '/[\p{L}\p{N}\']+/u', $text ) < $wpide_wpf_min_words ) {
        $process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
        $process->errors[ $form_data['id'] ][ $field_id ] = sprintf( 'Please write at least %d words so we can help.', $wpide_wpf_min_words );
    }
}, 10, 3 );
```

## Notes

Empty optional fields are skipped; required fields must reach the minimum.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Minimum Message Length in WPForms" 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/
