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

In this article

Validates if the JSON Schema pattern matches a value.

Parameters

$patternstringrequired
The pattern to match against.
$valuestringrequired
The value to check.

Return

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

Source

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

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

Changelog

VersionDescription
5.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.