How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Check if a JavaScript String Contains a Unicode Character
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Check if a JavaScript String Contains a Unicode Character
Web Development

How to Check if a JavaScript String Contains a Unicode Character

how7o
By how7o
Last updated: May 22, 2026
38 Min Read
JavaScript check Unicode character — regex, codePointAt, Unicode property escape
SHARE

To javascript check unicode character in a string, the cleanest one-liner is a regex against the Latin-1 range: /[^\u0000-\u00ff]/.test(str). It returns true if the string contains any character beyond plain ASCII + Latin-1 Supplement — emoji, CJK, Cyrillic, accented Latin Extended, etc. This guide also covers codePointAt (per-character check, surrogate-pair safe) and the modern \p{Emoji} property escape for emoji-specific detection.

Contents
  • TL;DR
  • The regex one-liner
  • Per-character check with codePointAt
  • Detecting emoji specifically
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 in Chromium, Firefox, Safari, and Node.js 22. Originally published 2022-12-19, rewritten and updated 2026-05-17.

TL;DR

// Any character outside Latin-1?
/[^\u0000-\u00ff]/.test("Hello");      // false
/[^\u0000-\u00ff]/.test("Héllo");      // false (é is Latin-1)
/[^\u0000-\u00ff]/.test("Hello 世界");  // true
/[^\u0000-\u00ff]/.test("Hi 👋");       // true

// Per-character (surrogate-pair safe)
"😀".codePointAt(0);                    // 128512 (0x1F600)
"😀".codePointAt(0) > 0xFF;             // true

// Emoji specifically
/\p{Emoji}/u.test("Hello 👋");          // true
/\p{Emoji}/u.test("Hello 世界");         // false

The regex one-liner

The character class [^\u0000-\u00ff] matches any character whose code point is outside the Latin-1 range (U+0000 through U+00FF). If the regex matches anywhere in the string, you have at least one non-Latin-1 character — what most people mean when they say “Unicode.”

function hasUnicode(str) {
  return /[^\u0000-\u00ff]/.test(str);
}

hasUnicode("Hello, world!");      // false
hasUnicode("Hello, 世界!");        // true
hasUnicode("café résumé");        // false (Latin-1 covers these)
hasUnicode("Hi 👋");              // true
JavaScript check Unicode character — regex vs codePointAt vs Unicode property escape

Per-character check with codePointAt

To check a specific character (rather than scan the whole string), codePointAt returns the Unicode code point as a number:

const str = "Hello, world!";
const cp = str.codePointAt(0);     // 72 (H)

if (cp > 0xFF) {
  console.log("First character is above Latin-1.");
}

Prefer codePointAt over the older charCodeAt: charCodeAt returns UTF-16 code units, which split emoji and other supplementary-plane characters into surrogate pairs. codePointAt returns the real code point and handles surrogates correctly.

Detecting emoji specifically

“Has any non-Latin-1 character” is broader than “has emoji.” If you specifically want emoji detection, use a Unicode property escape with the u flag:

/\p{Emoji}/u.test("Hi 👋");        // true
/\p{Emoji}/u.test("Hi 世界");       // false (CJK, not emoji)
/\p{Emoji_Presentation}/u.test(s); // emoji that render as emoji by default

Property escapes are supported in modern browsers and Node.js 12+. They map to the official Unicode property data, so the list stays current with new emoji releases.

Frequently asked questions

What counts as a ‘Unicode character’ here?

In this post, a Unicode character means any code point outside the Latin-1 range (U+0000 through U+00FF) — anything beyond plain ASCII plus the Latin-1 Supplement. Technically every JavaScript string character is Unicode (strings are UTF-16), but in practice you usually want to know whether the string contains characters that won’t fit in a one-byte encoding: accented Latin Extended, Cyrillic, CJK, emoji, etc.

Why is codePointAt safer than charCodeAt?

charCodeAt returns a UTF-16 code unit — for characters above U+FFFF (most emoji, supplementary CJK), it returns half of a surrogate pair, not the real code point. codePointAt returns the actual Unicode code point, correctly handling surrogate pairs. For modern Unicode work — especially anything involving emoji or rare scripts — codePointAt is the right default.

Does the regex /[^\u0000-\u00ff]/ match emoji?

Yes — emoji are code points well above U+00FF, so they match the non-Latin-1 character class. If you want to detect emoji specifically (rather than any non-Latin-1 character), use a Unicode property escape like /\p{Emoji}/u, which requires the u flag and modern browsers / Node 12+.

How do I count Unicode characters correctly?

str.length returns the UTF-16 code unit count, not the user-perceived character count. '😀'.length is 2, not 1. To count code points use [...str].length (the spread iterator yields code points), and for grapheme clusters (the actual visual characters) use Intl.Segmenter: [...new Intl.Segmenter().segment(str)].length.

Can I use this to validate input is ASCII-only?

Yes — flip the check. /^[\x00-\x7f]*$/.test(str) returns true only for pure-ASCII strings (no Latin-1 Supplement either). Useful for fields that must be transmitted over ASCII-only protocols (some SMS gateways, certain legacy database columns).

Related guides

  • How to Check if a JavaScript String Is a Valid URL
  • How to Format a Number with Decimals in JavaScript

References

MDN String.prototype.codePointAt: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt. Unicode property escapes: MDN Unicode property escapes.

TAGGED:JavaScriptValidation

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article List network devices on Linux — ip a and nmcli output side by side How to List Network Devices on Linux
Next Article Zip multiple files and directories on Linux — zip -r command How to Zip Multiple Files and Directories on Linux
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Prevent tab key from focusing on a link with tabindex=-1
Web Development

How to Skip a Link When Pressing Tab (tabindex=-1)

5 Min Read
PHP delete array element — unset, array_splice, array_filter, array_search
Web Development

How to Delete an Element from a PHP Array

7 Min Read
Extract a .tar.gz archive in PHP with PharData
Web Development

How to Extract a .tar.gz Archive in PHP

5 Min Read
Select all text in a contenteditable div on click
Web Development

How to Select All Text in a Contenteditable Div on Click

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?