diff --git a/README.md b/README.md
index 5b76b11..1fc6280 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,8 @@ pat-content-mirror
A pattern that provides rich dynamic functionality to a textarea. It is used
for single-line text input that should be able to wrap into the next line.
-Line breaks are not allowed and removed from the text input.
+Line breaks, tabs or multiple space characters are not allowed, removed from
+the text input and replaced with a single space character.
The main functionality is provided by maintaining a "mirror" element that
is updated every time the main textarea is changed. This element, which
diff --git a/src/pat-content-mirror.js b/src/pat-content-mirror.js
index d351233..3e64265 100644
--- a/src/pat-content-mirror.js
+++ b/src/pat-content-mirror.js
@@ -41,10 +41,14 @@ class Pattern extends BasePattern {
const el = ev.target;
const the_mirror = this.target;
- // Get value and remove line breaks and all vertical whitespace.
- // Instead add a single space so that separated lines are not glued
- // together.
- const value = el.value.replace(/[\r\n\v\f]+/g, " ");
+ // Get value and replace line breaks and all vertical whitespace with a
+ // single space. This wraps multiple lines into a single line while
+ // separating them with a space.
+ // Also replace any whitespace with a single space character to clean
+ // up the text from tabs, multiple whitespace or any other non-standard
+ // space character.
+ let value = el.value
+ value = value.replace(/[\r\n\v\f\s]+/g, " ");
// Write back the cleaned value to the textearea.
el.value = value;
diff --git a/src/pat-content-mirror.test.js b/src/pat-content-mirror.test.js
index 30bdd1b..78e8911 100644
--- a/src/pat-content-mirror.test.js
+++ b/src/pat-content-mirror.test.js
@@ -139,7 +139,7 @@ describe("pat-content-mirror", () => {
expect(mirror2.textContent).toBe("placeholder 2");
});
- it("Removes line breaks.", async () => {
+ it("Removes line breaks, tabs and multiple whitespace characters.", async () => {
document.body.innerHTML = `