It searches for at least one character without spaces.
/\S/.test(" "); // false /\S/.test(" "); // false /\S/.test(""); // false /\S/.test("foo"); // true /\S/.test("foo bar"); // true /\S/.test("foo "); // true /\S/.test(" foo"); // true /\S/.test(" foo "); // true
I assume that I assume that an empty line should only consider spaces.
If an empty line (which technically does not contain all spaces, because it does not contain anything), should pass the test, and then change it to ...
/\S|^$/.test(" "); // false /\S|^$/.test(""); // true /\S|^$/.test(" foo "); // true
user1106925
source share