rest_validate_json_schema_pattern()WP 5.6.0

Validates if the JSON Schema pattern matches a value.

No Hooks.

Return

true|false. True if the pattern matches the given value, false otherwise.

Usage

rest_validate_json_schema_pattern( $pattern, $value );
$pattern(string) (required)
The pattern to match against.
$value(string) (required)
The value to check.

Changelog

Since 5.6.0 Introduced.

rest_validate_json_schema_pattern() code WP 6.6.2

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

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