Title: rest_is_ip_address
Published: December 7, 2016
Last modified: May 20, 2026

---

# rest_is_ip_address( string $ip ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#wp--skip-link--target)

Determines if an IP address is valid.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#description)󠁿

Handles both IPv4 and IPv6 addresses.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#parameters)󠁿

 `$ip`stringrequired

IP address.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#return)󠁿

 string|false The valid IP address, otherwise false.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#source)󠁿

    ```php
    function rest_is_ip_address( $ip ) {
    	$ipv4_pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';

    	if ( ! preg_match( $ipv4_pattern, $ip ) && ! WpOrg\Requests\Ipv6::check_ipv6( $ip ) ) {
    		return false;
    	}

    	return $ip;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api.php#L1500)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api.php#L1500-L1508)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#related)󠁿

| Used by | Description | 
| [rest_validate_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_validate_value_from_schema/)`wp-includes/rest-api.php` |

Validate a value based on a schema.

  | 
| [WP_REST_Comments_Controller::prepare_item_for_database()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/prepare_item_for_database/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Prepares a single comment to be inserted into the database.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rest_is_ip_address/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frest_is_ip_address%2F)
before being able to contribute a note or feedback.