[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/isWellFormed [Back]  [Original]

String.prototype.isWellFormed() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String.prototype.isWellFormed()

Baseline

202310

isWellFormed() String

js
isWellFormed()

true false

JavaScript UTF-16 UTF-16 UTF-16 Unicode

isWellFormed() isWellFormed() toWellFormed() isWellFormed()

isWellFormed()

js
const strings = [
  // 
  "ab\uD800",
  "ab\uD800c",
  // 
  "\uDFFFab",
  "c\uDFFFab",
  // 
  "abc",
  "ab\uD83D\uDE04c",
];

for (const str of strings) {
  console.log(str.isWellFormed());
}
// Logs:
// false
// false
// false
// false
// true
// true

encodeURI()

encodeURI isWellFormed() encodeURI()

js
const illFormed = "https://example.com/search?q=\uD800";

try {
  encodeURI(illFormed);
} catch (e) {
  console.log(e); // URIError: URI malformed
}

if (illFormed.isWellFormed()) {
  console.log(encodeURI(illFormed));
} else {
  console.warn(""); // 
}

ECMAScript 2027 LanguageSpecification
# sec-string.prototype.iswellformed


Web Proxy Viewer  |  New URL  |  Original Page