If you want to see if the file contains all spaces or is empty, I would recommend checking the inverse and inverting the result. This way you do not have to worry about special cases around an empty string.
all spaces are the same as without spaces, therefore:
function isWhitespaceOrEmpty(text) { return !/[^\s]/.test(text); }
If you do not need empty lines, you can change it a little:
function isWhitespaceNotEmpty(text) { return text.length > 0 && !/[^\s]/.test(text); }
coderjoe Jul 23 '09 at 15:18 2009-07-23 15:18
source share