Newly availableNewly available. Not yet supported in older browsers; verify your target environments before adopting.

Overview

The isWellFormed() method of strings returns a boolean indicating if the string contains any Unicode lone surrogates. The toWellFormed() method returns a new string where all lone surrogates are replaced by the Unicode replacement character.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
111
111
119
16.4
111
16.4
Built-in object

The toWellFormed() method of String values returns a string where all lone surrogates of this string are replaced with the Unicode replacement character U+FFFD.

111
111
119
16.4
111
16.4
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
'Hello'.isWellFormed();          // true
'\uD800'.isWellFormed();         // false (isolated surrogate)
'\uD800'.toWellFormed();         // '\uFFFD'

Live demo

not-positive Unicode. Detect

IsWellFormed Use, string to not-completeall saroge-tpea that include or check..

PreviewFullscreen

safeall shape notation. autoconvert

ToWellFormed use, not-positive character replacecharacter to convertsafeall to like to..

PreviewFullscreen

positivealways string. confirm

Normal. String(emojiinclude) that positivealways shape notation in exists and inspect it..

PreviewFullscreen

Use cases

  • Using String isWellFormed() and toWellFormed()

    The isWellFormed() method of strings returns a boolean indicating if the string contains any Unicode lone surrogates. The toWellFormed() method returns a new string where all lone surrogates are replaced by the Unicode replacement character.

Cautions

  • Not supported in older browsers. Verify your target environments before adopting.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features