# Validate the Checkout Phone Number Format

> Rejects billing phone numbers that contain letters or too few digits on the classic checkout, so you get numbers you can actually call.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, validation, phone
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-validate-phone/

## Code

```php
add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) {
    $min_digits = 7; // Minimum number of digits.

    if ( empty( $data['billing_phone'] ) ) {
        return;
    }

    $phone  = (string) $data['billing_phone'];
    $digits = preg_replace( '/\D/', '', $phone );

    if ( preg_match( '/[^0-9\s\-\.\(\)\+]/', $phone ) || strlen( $digits ) < $min_digits ) {
        $errors->add( 'validation', 'Please enter a valid phone number.' );
    }
}, 10, 2 );
```

## Notes

Change $min_digits to suit your country. Spaces, dashes, dots, brackets and a leading + are allowed.

## How to use it

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