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.
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 |
Syntax
'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..
safeall shape notation. autoconvert
ToWellFormed use, not-positive character replacecharacter to convertsafeall to like to..
positivealways string. confirm
Normal. String(emojiinclude) that positivealways shape notation in exists and inspect it..
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.
Related links
Powered by web-features