### [How to Deny Specific Phone Numbers From Submitting](https://wpforms.com/developers/how-to-deny-specific-phone-numbers-from-submitting/)

**Published:** July 27, 2021
**Author:** Editorial Team

**Excerpt:** This tutorial will show you how you can deny certain phone numbers from submitting entries on your forms with this small PHP snippet. 

**Content:**

## Introduction

Would you like to deny specific phone numbers from submitting entries on your forms? You can easily create a small PHP snippet that will block the form from submitting if the phone number is found on the denial list. In this tutorial, we’ll walk you through the steps on how to achieve this.

## Creating your form

First, you’ll need to begin by creating a new form and adding your fields to this form which will include a **Phone** form field.

In our tutorial, we’re going to use the **Smart** format for our **Phone** field.

If you need assistance in creating your form, [please see this documentation](https://wpforms.com/docs/creating-first-form/ "How to Create Your First Form").

![create your form add your phone field and the rest of your fields](https://wpforms.com/wp-content/uploads/2021/07/wpforms-add-phone-number.jpg)

## Denying specific phone numbers

In order to deny specific phone numbers, you’ll need to add this snippet to your site.

If you need help in how to add snippets to your site, [please see this tutorial](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

```

/*
 * Deny specific phone numbers from your WPForms.
 *
 * @link https://wpforms.com/developers/how-to-deny-specific-phone-numbers-from-submitting/
*/
  
function wpf_dev_blacklist_phone( $field_id, $field_submit, $form_data ) {
 
    // List each number in this array and separate with a comma using one of the formats detailed below
 
    // Smart         Phone Format - +12025550164
    // US            Phone Format - (202) 555-0164
    // International Phone Format - 2025550164
    
    // Optional, you can limit to specific forms. Below, we restrict output to form ID 5
    // Remove this section if you wish to run on all forms
    if ( absint( $form_data[ 'id' ] ) !== 5 ) {
        return;
    }
 
    // Add your phone numbers separated by a comma
    $phone_blacklist = array( 
            '+12025550164',
             
    );
  
    if( in_array( $field_submit, $phone_blacklist ) ) { 
        wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'Phone not accepted!', 'wpforms' );
        return;
    }
}
 
add_action('wpforms_process_validate_phone', 'wpf_dev_blacklist_phone', 10, 3 );
```

This snippet will only process on the form ID **5**. You’ll need to update this ID to match your own form ID. If you need help in finding your ID, [please review this helpful guide](https://wpforms.com/developers/how-to-locate-form-id-and-field-id/ "How to Locate Form ID and Field ID").

The **$phone\_blacklist** is a list of numbers that you will create which will stop the form from submitting if one of the phone numbers entered on the form matches a number in this list.

The above snippet is based off using the **Smart Format** for the **Phone** field. Please see the comments in the snippet above to learn how to format the array if using the **US** or **International Format**.

![with this snippet you can now deny specific phone numbers from submitting your form](https://wpforms.com/wp-content/uploads/2021/07/wpforms-deny-phone-numbers.jpg)

And that’s all you need! Would you like to also turn the phone number into a link inside the email notification? Take a look at our tutorial on [How to Make Phone Numbers a Link in Email Notifications](https://wpforms.com/developers/how-to-make-phone-numbers-a-link-in-email-notifications/ "How to Make Phone Numbers a Link in Email Notifications").

## Related

Action Reference: [wpforms\_process\_validate\_phone](https://wpforms.com/developers/wpforms_process_validate_phone/ "Using the wpforms_process_validate_phone action")

**Categories:** Tutorials

**Tags:** PHP

---

