Title: valid_unicode
Published: April 25, 2014
Last modified: February 24, 2026

---

# valid_unicode( int $i ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#changelog)

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

Determines if a Unicode codepoint is valid.

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

The definition of a valid Unicode codepoint is taken from the XML definition:

> Characters
> … Legal characters are tab, carriage return, line feed, and the legal characters
> of Unicode and ISO/IEC 10646.
> … Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#
> xFFFD] | [#x10000-#x10FFFF]

### 󠀁[See also](https://developer.wordpress.org/reference/functions/valid_unicode/?output_format=md#see-also)󠁿

 * [https://www.w3.org/TR/xml/#charsets](https://www.w3.org/TR/xml/#charsets/)

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

 `$i`intrequired

Unicode codepoint.

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

 bool Whether or not the codepoint is a valid Unicode codepoint.

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

    ```php
    function valid_unicode( $i ) {
    	$i = (int) $i;

    	return (
    		0x9 === $i || // U+0009 HORIZONTAL TABULATION (HT)
    		0xA === $i || // U+000A LINE FEED (LF)
    		0xD === $i || // U+000D CARRIAGE RETURN (CR)
    		/*
    		 * The valid Unicode characters according to the XML specification:
    		 *
    		 * > any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
    		 */
    		( 0x20 <= $i && $i <= 0xD7FF ) ||
    		( 0xE000 <= $i && $i <= 0xFFFD ) ||
    		( 0x10000 <= $i && $i <= 0x10FFFF )
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/kses.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/kses.php#L2345)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/kses.php#L2345-L2361)

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

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

## User Contributed Notes

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