Title: rest_validate_json_schema_pattern
Published: December 9, 2020
Last modified: August 20, 2026

---

# rest_validate_json_schema_pattern( string $pattern, string $value ): bool

## In this article

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

Validates if the JSON Schema pattern matches a value.

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

 `$pattern`stringrequired

The pattern to match against.

`$value`stringrequired

The value to check.

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

 bool True if the pattern matches the given value, false otherwise.

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

    ```php
    function rest_validate_json_schema_pattern( $pattern, $value ) {
    	$escaped_pattern = str_replace( '#', '\\#', $pattern );

    	return 1 === preg_match( '#' . $escaped_pattern . '#u', $value );
    }
    ```

[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.1/src/wp-includes/rest-api.php#L1855)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api.php#L1855-L1859)

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

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

Validates a string value based on a schema.

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

Finds the schema for a property using the patternProperties keyword.

  |

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

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

## User Contributed Notes

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