rest_validate_json_schema_pattern()
Validates if the JSON Schema pattern matches a value.
No Hooks.
Returns
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() rest validate json schema pattern code WP 6.9.1
function rest_validate_json_schema_pattern( $pattern, $value ) {
$escaped_pattern = str_replace( '#', '\\#', $pattern );
return 1 === preg_match( '#' . $escaped_pattern . '#u', $value );
}