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

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 String values returns a boolean indicating whether this string contains any lone surrogates.

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.