# Validate Phone Numbers in Fluent Forms

> Checks Fluent Forms phone fields for a realistic number of digits and only the characters phone numbers use, instead of accepting any text.

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

## Code

```php
$wpide_ff_phone_fields = array( 'phone' );
$wpide_ff_phone_min    = 7;
$wpide_ff_phone_max    = 15;

add_filter( 'fluentform/validation_errors', function ( $errors, $data ) use ( $wpide_ff_phone_fields, $wpide_ff_phone_min, $wpide_ff_phone_max ) {
    foreach ( $wpide_ff_phone_fields as $name ) {
        $phone = isset( $data[ $name ] ) && is_string( $data[ $name ] ) ? trim( $data[ $name ] ) : '';
        if ( '' === $phone ) {
            continue;
        }

        $digits = strlen( preg_replace( '/\D/', '', $phone ) );

        if ( ! preg_match( '/^\+?[0-9\s().\-]+$/', $phone ) || $digits < $wpide_ff_phone_min || $digits > $wpide_ff_phone_max ) {
            $errors[ $name ] = array( 'Please enter a valid phone number.' );
        }
    }

    return $errors;
}, 10, 2 );
```

## Notes

Set the phone field names at the top; empty optional fields are skipped.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Validate Phone Numbers in Fluent 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/
