unicode

Invisible characters: why your text “just doesn’t work”

Identify the invisible characters (ZWSP, ZWNJ, RLM, BOM) that break searches, forms and exports, and remove them without losing anything useful.

Published on · Updated on · 2 min read

A field that rejects a correct value, a filter that finds nothing, a CSV where one column shifts: three frequent symptoms of the same cause, the presence of invisible characters.

The problem

You copy a phone number from a website, paste it into a form, and it is rejected. You check: the number looks right. In reality it contains a non-breaking space (U+00A0) or a word joiner (U+2060) that is not part of the allowed characters.

The most frequent invisible characters

  • U+200B (ZWSP): zero-width space, inserted by some editors to allow line breaks inside a long URL.
  • U+200C (ZWNJ) and U+200D (ZWJ): joining controls used in Arabic and Persian to prevent or force a connection.
  • U+200E (LRM) and U+200F (RLM): direction marks, common in bilingual Arabic/Latin text.
  • U+00A0 (NBSP): non-breaking space, frequent in text pasted from the web and in layout documents.
  • U+FEFF (BOM): byte order mark, present at the start of some exported files.
  • U+00AD (soft hyphen): conditional hyphen, invisible except at the end of a line.

Why it breaks systems

String comparison is strict: “213555123456” and “213555 123456” (with a non-breaking space) are two different strings. A filter looking for ^[0-9]+$ fails, alphabetical sorting puts the entry elsewhere, a CSV import treats the character as a separator.

The rule: you do not “see” the problem, you measure it. A detector shows the Unicode code and the exact position of every invisible character.

The cleaning method

  1. Detect: paste the text, note the codes and the number of occurrences.
  2. Decide: not every invisible character should disappear. ZWNJ is sometimes required in Persian and in certain Arabic spellings; a BOM at the start of a UTF-8 file may be needed by legacy software.
  3. Remove with a tool that reports what it removed, and only for the categories you chose.
  4. Verify: compare character counts before and after, and check the visual rendering.

Cases where you must keep them

In Persian text the ZWNJ (نیمفاصله) is orthographically significant: removing it turns « میروم » into « میروم ». In Arabic text, RLM marks can be replaced by HTML markup (dir="rtl", <bdi>), which is preferable. In files for software that requires a BOM, keep it.

Prevention

Avoid copying from rich web pages when entering structured data. For batch processing, prefer a script or spreadsheet that applies the same cleaning rule to every row instead of cleaning manually, line by line.

The invisible character detector lists codes and positions, the remover applies the cleaning with a report, and the Unicode inspector details every character of a short text (name, category, UTF-8 encoding).